hhh*_*hhh 1 plot regression r least-squares
y<-c(0.0100,2.3984,11.0256,4.0272,0.2408,0.0200);
x<-c(1,3,5,7,9,11);
d<-data.frame(x,y)
myLm<-lm(x~y**2,data=d)
plot(d)
lines(x,lm(y ~ I(log(x)) + x,data=d)$fitted.values)
lines(x,lm(y ~ I(x**2) + x,data=d)$fitted.values) % not quite right, smooth plz
Run Code Online (Sandbox Code Playgroud)
应该是顺利的情节,有些不对劲.

帮助者的问题
您需要predict在拟合点之间插入预测.
d <- data.frame(x=seq(1,11,by=2),
y=c(0.0100,2.3984,11.0256,4.0272,0.2408,0.0200))
lm1 <-lm(y ~ log(x)+x, data=d)
lm2 <-lm(y ~ I(x^2)+x, data=d)
xvec <- seq(0,12,length=101)
plot(d)
lines(xvec,predict(lm1,data.frame(x=xvec)))
lines(xvec,predict(lm2,data.frame(x=xvec)))
Run Code Online (Sandbox Code Playgroud)

强制ggplot2方法:
library(ggplot2)
qplot(x,y)+stat_smooth(method="lm", formula="y~poly(x,2)", se=FALSE)
Run Code Online (Sandbox Code Playgroud)
