作者jimshsu (jims)
看板Statistics
标题Re: [问题] 请问计算大量的线性回归.....
时间Mon May 21 10:35:56 2007
解法
用biglm
**************
library(biglm)
path<-choose.dir(default = "", caption = "Select data folder")
ptm <- proc.time()
filelist<-dir(path,full.names = TRUE)
if(length(filelist) > 0){
ff<-de~ID
if( length(filelist) > 1 ){
df <- scan(filelist[1], what = list("", double(0)),sep=",")
de<-df[[2]]
rm(df)
total<-length(de)
ID<-1:total
lmf<-data.frame(lmf=cbind(de,ID))
res<-biglm(ff,lmf)
print(coef(res)[[1]])
print(coef(res)[[2]])
idcount <- total
for(i in 2:length(filelist))
{
df <- scan(filelist[i], what = list("", double(0)),sep=",")
de<-df[[2]]
rm(df)
total<-length(de)
ID<-seq(idcount+1,idcount+total,by=1)
idcount <-idcount+total
lmf<-data.frame(lmf=cbind(de,ID))
res<-update(res,lmf)
print(filelist[i])
print(i)
print(coef(res)[[1]])
print(coef(res)[[2]])
}
}else{
df <- scan(filelist[1], what = list("", double(0)),sep=",")
de<-df[[2]]
rm(df)
total<-length(de)
ID<-1:total
lmf<-data.frame(lmf=cbind(de,ID))
res<-biglm(ff,lmf)
}
print(coef(res)[[1]])
print(coef(res)[[2]])
}
proc.time() - ptm
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.69.175.253