Skip to content
Prev 333881 / 398513 Next

Multiple regressions with changing dependent variable and time span

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 rep(NA,9)},by.column=FALSE,align="right")))
dim(res2)
#[1]? 123 3006
?334*9
#[1] 3006

lst2New <- lapply(split(seq(3006),((seq(3006)-1)%%9)+1),function(x) {x1 <- res2[,x]; colnames(x1) <- paste(colnames(x1),1:334,sep="_");x1})
sapply(lst2New,ncol)
#? 1?? 2?? 3?? 4?? 5?? 6?? 7?? 8?? 9 
#334 334 334 334 334 334 334 334 334 
lst2New[[1]][1:4,1:4]
#???? (Intercept)_1 (Intercept)_2 (Intercept)_3 (Intercept)_4
#[1,]??????????? NA??? -0.3295765??? -0.7025259??????????? NA
#[2,]??????????? NA???? 0.1217360??? -1.5221660??????????? NA
#[3,]??????????? NA???? 0.3192466??? -1.3586341??????????? NA
#[4,]??????????? NA???? 0.2618476??? -0.9698798??????????? NA


A.K.
On Sunday, December 1, 2013 9:33 PM, nooldor <nooldor at gmail.com> wrote:
Hi,

actually, do you remember yesterday code you build for me?
it was:

dat1<-read.csv("Book2.csv", header=T)
pval=summary(l1)$coef[,4], rsquare=summary(l1)$r.squared) } else 
rep(NA,9)},by.column=FALSE,align="right")))
(boo2.xls is? attached in this e-mail previously, just need to open it in excel and save as csv)
then we have result res1 as matrix 41082 x 9
(this 41082 = 123observations in time x 334objects)
now I need to separate this matrix res1 into 9 different matrices each one containing 123 obs x 334 variables 



maybe reshape() would be useful ...

... let me know if I described it clearly
On 2 December 2013 03:17, arun <smartpink111 at yahoo.com> wrote:
#or