[R] Question about lmer

Julia Proudnikova prudnikova at itcwin.com
Mon Jun 18 12:02:13 CEST 2007


Hello,

We have a problem with function lmer. This is our code:

Get_values<-function(ff_count, fixed_factors, rf_count, random_factors, y_values)
{       
  SA<-matrix(as.array(c(fixed_factors, random_factors)), ncol=3)
  data<-as.data.frame(SA)
  y<-as.array(y_values)

  dd<-data.frame(SA)
  for(i in 1:(ff_count+rf_count)){
    dd[,i]<-as.factor(data[,i])
  }
  
  fit_full=lmer(y~dd[,1]+dd[,2]+(1|dd[,3]),method="ML")    
  fit_full
}

A<-c(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1)
B<-c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1)
C<-c(0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1)
Y<-c(5,3,4,1,1,2,6,1,5,3,7,1,2,3,1,1,5,3,4,1,1,2,6,1,5,3,7,1,2,3,1,1)
r<-Get_values(2, c(A,B),1,c(C),Y)
r 

R output:
Error in inherits(x, "factor") : object "dd" not found

Can this function work with random array? Because this code is
working:

D<-as.factor(data[,3])
fit_full=lmer(y~dd[,1]+dd[,2]+(1|D),method="ML")
 

-- 
Truly yours,
Julia                 mailto:prudnikova at itcwin.com



More information about the R-help mailing list