[R] Linear Regression

Douglas Bates bates at stat.wisc.edu
Fri Mar 6 13:20:52 CET 2009


On Fri, Mar 6, 2009 at 6:07 AM, Sueli Rodrigues <srodrigu at esalq.usp.br> wrote:
>
> Hi, I have the following file, and I need to work out the linear
> regression for each sample. I tried the model(*) and receive the error
> message (**):
>> data=split(mydata,rep(1:(nrow(mydata)/6),each=6))
>> arrang.linear=lapply(data,lm,formula=KA~PA)
> Erro em storage.mode(y) <- "double" :
>  invalid to change the storage mode of a factor
> Além disso: Warning message:
> In model.response(mf, "numeric") :
>  using type="numeric" with a factor response will be ignored
>
> SAMPLE  PA      KA
> 2       0.917   11.261
> 2       0.823   11.010
> 2       0.803   10.381
> 2       0.744   10.208
> 2       0.697   10.006
> 2       0.681   9.916
> 3       0.789   10.271
> 3       0.702   10.076
> 3       0.692   9.990
> 3       0.646   9.779
> 3       0.620   9.749
> 3       0.608   9.708
> 4       1.052   11.779
> 4       0.941   11.249
> 4       0.881   10.140
> 4       0.824   10.052
> 4       0.790   9.859
> .         .       .
> .         .       .
> .         .       .
> 80      0.499   9.819

The lmList function in the package nlme is designed to handle
situations like this.  Try

library(nlme)
modlst <- lmList(KA ~ PA | SAMPLE, data)




More information about the R-help mailing list