Hi I want to perform several regressions under different conditions. I have achieved to do this successfully but when I get the list with all coefficients, the names of the levels are missing whenever I use more than one level factor. However, if I only use one factors names remain .
What I want is calculate all parameters under two conditions and obviously get the names. I want to do this via looping because my data is much more complex than this.
library(bear)
model<-function(A,mu) {
A+mu*time
}
mod <- ln_rel.cc ~A+mu*time
rep<- c("r1","r2","r3","r4","r5")
Medium<-c("A","B")
time<-c(seq(from=0, to=39,by=1))
ln_rel.cc<-model(A=1,mu=0.4)
MedTest<-cbind(rep,Medium,time,ln_rel.cc )
MedTest<-data.frame(MedTest)
MedTest$time<-as.numeric(MedTest$time)
MedTest$ln_rel.cc<-as.numeric(MedTest$ln_rel.cc)
head(MedTest)
values<-NULL
##one factor regression
for(M in levels(MedTest$Medium)){
values[M]<-list((summary(lm(ln_rel.cc ~time, MedTest[ MedTest$Medium==M ,]
))$coef))
}
values
values<-NULL
##Two factors regression
for(M in levels(MedTest$Medium)){
for (R in levels(MedTest$rep)){
values[M[R]]<-list((summary(lm(ln_rel.cc ~time, MedTest[MedTest$rep==R & MedTest$Medium==M ,]
))$coef))
}
}
values
Thanks for the help