Re: [R] Multiple regressions with changing dependent variable and time span

2013-12-01 Thread arun
Hi, I guess you wanted something like this: res2 <- do.call(cbind,lapply(lst2,  function(x) rollapply(x,width=32,FUN=function(z) {z1 <- as.data.frame(z); if(!sum(!!rowSums(is.na(z1 {l1 <-lm(r~F.1+F.2+F.3,data=z1); c(coef(l1), pval=summary(l1)$coef[,4], rsquare=summary(l1)$r.squared) } else

Re: [R] Multiple regressions with changing dependent variable and time span

2013-12-01 Thread arun
Hi, Try: dat1 <- read.table(text="A    B C D r.1  x1    x2   x3 r.1  x4    x5    x6 r.2  x7    x8    x9 r.2  x10  x11 x12 r.3  x13  x14 x15 r.3  x16  x17 x18",header=TRUE,stringsAsFactors=FALSE)  dat2 <- do.call(cbind,split(dat1,dat1$A)) colnames(dat2) <- gsub(".*\\.","",colnames(dat2)) A.

Re: [R] Multiple regressions with changing dependent variable and time span

2013-12-01 Thread nooldor
Yes. Thank you once again. With this: > res2 <- do.call(cbind,lapply(lst2, > function(x) > rollapply(x,width=32,FUN=function(z) {z1 <- as.data.frame(z); > if(!sum(!!rowSums(is.na(z1 {l1 <-lm(r~F.1+F.2+F.3,data=z1); > c(coef(l1), pval=summary(l1)$coef[,4], rsquare=summary(l1)$r.squared) } > el

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-30 Thread arun
Hi, No problem. In that case, each column will be a list.  For example if I take the first element of `lst2` dW1 <- rollapply(lst2[[1]],width=32,FUN=function(z) {z1 <- as.data.frame(z); if(!sum(!!rowSums(is.na(z1 {l1 <-lm(r~F.1+F.2+F.3,data=z1); durbinWatsonTest(l1,max.lag=3) } else rep(NA,

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-30 Thread nooldor
Hey! Yes, only the D-W test takes so much time, did not check it yet I checked results (estimates) with manually run regressions (in excel) and they are correct. I only change the "width" to 31 and "each=123" to 124, cause it should be ((154-31)+1) x 334 = 41416 matrix with the lag in D-W test I

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-30 Thread arun
Hi, I was able to read the file after saving it as .csv.  It seems to work without any errors. dat1<-read.csv("Book2.csv", header=T) ###same as previous lst1 <- lapply(paste("r",1:334,sep="."),function(x) cbind(dat1[,c(1:3)],dat1[x])) lst2 <- lapply(lst1,function(x) {colnames(x)[4] <-"r";x} )

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-30 Thread arun
Hi, #1 & 2: set.seed(432) dat1 <- as.data.frame(matrix(sample(c(1:60,NA),154*337,replace=TRUE),ncol=337))  colnames(dat1) <- c(paste("F",1:3,sep="."),paste("r",1:334,sep=".")) lst1 <- lapply(paste("r",1:334,sep="."),function(x) cbind(dat1[,c(1:3)],dat1[x]))  lst2 <- lapply(lst1,function(x) {

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-30 Thread nooldor
Hi, Thanks for reply! Three things: 1. I did not write that some of the data has more then 31 NA in the column and then it is not possible to run lm() Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases In this case program should return "NA" symbol and go

Re: [R] Multiple regressions with changing dependent variable and time span

2013-11-29 Thread arun
Hi, The link seems to be not working.  From the description, it looks like: set.seed(432) dat1 <- as.data.frame(matrix(sample(200,154*337,replace=TRUE),ncol=337))  colnames(dat1) <- c(paste("F",1:3,sep="."),paste("r",1:334,sep=".")) lst1 <- lapply(paste("r",1:334,sep="."),function(x) cbind(dat1[,c

[R] Multiple regressions with changing dependent variable and time span

2013-11-29 Thread nooldor
Hi all! I am just starting my adventure with R, so excuse me naive questions. My data look like that: I have 3 independent variables (F.1, F.2 and F.3) and 334 other variables (r.1, r.2, ... r.334) - each one of these will be dep