Re: [問題] 請問計算大量的線性迴歸.....
解法
用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
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):