# \donttest{
data(data1)
da <- data1
do1 <- da[1:30,]
do2 <- da[31:70,]
do3 <- da[71:100,]
m1 <- speedlm(y ~ factor(fat1) + x1 + x2, data = do1)
m1 <- update(m1, data = do2)
m1 <- update(m1, data = do3)
m2 <- lm(y ~ factor(fat1) + x1 + x2, data = data1)
summary(m1)
summary(m2)
# as before but recursively
make.data <- function(filename, chunksize,...){
conn <- NULL
function(reset=FALSE, header=TRUE){
if(reset){
if(!is.null(conn)) close(conn)
conn<<-file(filename,open="r")
} else{
rval <- read.table(conn, nrows=chunksize,header=header,...)
if (nrow(rval)==0) {
close(conn)
conn<<-NULL
rval<-NULL
}
return(rval)
}
}
}
tmp_da<-tempfile("da",fileext=".txt")
write.table(da,tmp_da,col.names=TRUE,row.names=FALSE,quote=FALSE)
dat <- make.data(tmp_da,chunksize=30,col.names=c("y","fat1","x1", "x2"))
dat(reset=TRUE)
da2 <- dat(reset=FALSE)
# the first model runs on the first 30 rows.
m3 <- speedlm(y ~ factor(fat1) + x1 + x2, data=da2)
# the last three models run on the subsequent 30, 30 and 10 rows, respectively
for (i in 1:3){
da2 <- dat(reset=FALSE, header=FALSE)
m3 <- update(m3, data=da2, add=TRUE)
}
all.equal(coef(m1),coef(m3))
# }
Run the code above in your browser using DataLab