|
发表于 2016-6-2 19:36:51
|
显示全部楼层
本帖最后由 zhigaowu 于 2016-6-3 07:47 编辑
setwd("c:/work")
data <- read.table ("Hollywood.txt", header = TRUE)
data
attach(data)
y<-data$X1
x1<-data$X2
x2<-data$X3
x3<-data$X4
fit1 <- lm (y~x1)
fit2 <- lm (y~x2)
fit3 <- lm (y~x3)
fit4 <- lm (y~x1 + x2 + x3)
fit5 <- lm (y~x1 + x2 )
summary (fit1)
summary (fit2)
summary (fit3)
summary (fit4)
summary (fit5)
#####################################################
#refrence: http://www.walkingrandomly.com/?p=5254
#只绘了前三项图
par(bg=colors()[1])
plot(x1, y)
new = data.frame(x1 = seq(min(x1),max(x1),len=2))
lines(new$x1,predict(fit1,newdata=new))
Sys.sleep(5)
par(bg=colors()[399])
plot(x2, y)
new = data.frame(x2 = seq(min(x2),max(x2),len=2))
lines(new$x2,predict(fit2,newdata=new))
Sys.sleep(3)
par(bg=colors()[652])
plot(x3, y)
new = data.frame(x3 = seq(min(x3),max(x3),len=2))
lines(new$x3,predict(fit3,newdata=new))
Sys.sleep(3)
|
|