Re: [問題] 請問計算大量的線性迴歸.....

看板Statistics作者 (jims)時間18年前 (2007/05/21 10:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
解法 用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
文章代碼(AID): #16KGMDu2 (Statistics)
文章代碼(AID): #16KGMDu2 (Statistics)