[R] how to fit model to split data and get residual plots
Henrique Dallazuanna
wwwhsd at gmail.com
Tue Jan 15 20:36:30 CET 2008
Try this:
par(mfrow=c(4,4))
lapply(by(data3, list(data3$var1,data3$expt), function(x) lm(diameter
~ day, data = x)), plot)
or:
par(mfrow=c(4,4))
lapply(lapply(split(data3, list(data3$var1, data3$exp)), lm,
form="diameter ~ day"), plot)
On 15/01/2008, Eduardo S. G. Mizubuti <mizubuti at ufv.br> wrote:
>
> I have a data set with the following structure (with many more obs.):
>
> var1 expt day diameter
> 1 1 2 0.5
> 1 1 3 0.9
> 1 1 4 1.3
> 1 1 5 1.7
> 1 2 2 0.3
> 1 2 3 0.5
> 1 2 4 0.9
> 1 2 5 1.6
> 2 1 2 0.7
> 2 1 3 1.2
> 2 1 4 1.6
> 2 1 5 2.3
> 2 2 2 0.4
> 2 2 3 0.8
> 2 2 4 1.6
> 2 2 5 3.2
>
> I can get separate regression analysis for each level of var1 and expt
> with the command:
>
> by(data3, data3$var1:data3$expt, function(x) lm(diameter ~ day, data =
> x))
>
> How can I get residual plots for each combination var1*expt generated
> above?
>
> Thanks!
> Eduardo
>
>
>
>
>
> --
> Eduardo S. G. Mizubuti
> Departamento de Fitopatologia
> Universidade Federal de Viçosa
> 36570-000 Viçosa, MG Brasil
> tel.: +55 31 3899 1090
> fax: +55 31 3899 2240
> e-mail: mizubuti at ufv.br
>
> ______________________________________________
> R-help at 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list