R making predictions from lm

#using R

#Prepare simulation data:

a <- 1:5

b <- a^2

#predicting model

model <- lm(b~poly(a,2,raw=T))

predicted <- predict(model,data.frame(x=a),interval='confidence',level=0.99)

plot(a,b)

lines(a,predicted[,1],col="green",lwd=3)

#use the model coefficients to predict the newdata

summary(model)

x<-5:10 #newdata

y<-model$coefficients[1]+model$coefficients[2]*x+model$coefficients[3]*x^2

print(y)

posted on 2016-12-03 06:05  Vermont  阅读(99)  评论(0编辑  收藏  举报

导航