Skip to content
Back to formatted view

Raw Message

Message-ID: <40e66e0b0903060420l7faaddbav7a5eee21ba3dfdbd@mail.gmail.com>
Date: 2009-03-06T12:20:52Z
From: Douglas Bates
Subject: Linear Regression
In-Reply-To: <1620.143.107.219.61.1236341234.squirrel@carpa.ciagri.usp.br>

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)