Dear Sueli,
Assuming that your data is in a data frame called "mydata", something like
the following should work:


# splitting the data by SAMPLE
msp<-with(mydata,split(mydata,SAMPLE))

# linear models by sample
models<-lapply(msp,function(x) lm(KA ~ PA, data = x))

# linear models by sample
models<-lapply(msp,function(x) lm(KA ~ PA, data = x))
models

# summaries
lapply(models,summary)

# to access the models for the first sample and plot its residuals
par(mfrow=c(2,2))
plot(models[[1]])  # to access a different sample, change the number "1"

HTH,

Jorge


On Fri, Mar 6, 2009 at 7:07 AM, Sueli Rodrigues <srodr...@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
>
> Sueli Rodrigues
>
> Eng. Agrônoma - UNESP
> Mestranda - USP/ESALQ
> PPG-Solos e Nutrição de Plantas
> Fones (19)93442981
>      (19)33719762
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to