[R] Problems with abline adding regression line to a graph

Petr Pikal petr.pikal at precheza.cz
Fri Nov 4 08:50:56 CET 2005


Hi

On 3 Nov 2005 at 16:03, CG Pettersson wrote:

Date sent:      	Thu, 03 Nov 2005 16:03:05 +0100
From:           	CG Pettersson <cg.pettersson at evp.slu.se>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] Problems with abline adding regression line to a graph

> Hello all,
> 
> R2.1.1, W2k
> 
> I try to make a plot of a simple regression model in this way:
> 
>  > with(njfA_bcd, {
> + plot(TC_OS.G31,Prot,cex = 2, col = "red", xlab= "TC/OS at GS32",
> + ylab="Grain crude protein (CP)")
> + })
> 
> This part works well and produces the datapoints as red circles.
> When I try to add a line, using a fitted linear model in a way
> that works perfect with other variables in the same dateset the
> following happens:
> 
>  > with(njfA_bcd, {
> +    abline(lm(predict(m1tc) ~ TC_OS.G31), lty = 1, col = "red")
> + })
> Error in model.frame(formula, rownames, variables, varnames, extras,
> extranames,  :
>         variable lengths differ
> 
> And this means?
> 
> There exists missing values for TC_OS.G31 in the dataset. From the
> beginning m1tc was a lm() object, which gave the same Error message.
> To try to fix the problem I changed to lme() and used
> na.action=na.omit explicitely, but this didn´t help.

na.action=na.exclude

should help.

It should be probably mentioned in lm help page, at least as a 
hyperlink to na.* parametrs.

HTH
Petr



> 
> Here is the summary of m1tc:
> 
>  > summary(m1tc)
> Linear mixed-effects model fit by REML
>  Data: njfA_bcd
>        AIC      BIC    logLik
>   209.4914 219.0692 -100.7457
> 
> Random effects:
>  Formula: ~1 | Trial
>         (Intercept)  Residual
> StdDev:    1.242184 0.6520464
> 
> Fixed effects: Prot ~ TC_OS.G31
>                 Value Std.Error DF   t-value p-value
> (Intercept)  14.86209  0.957630 68 15.519662       0
> TC_OS.G31   -24.22286  4.792801 68 -5.054008       0
>  Correlation:
>           (Intr)
> TC_OS.G31 -0.935
> 
> Standardized Within-Group Residuals:
>         Min          Q1         Med          Q3         Max
> -1.68329774 -0.73751040 -0.05600477  0.68301243  2.21693174
> 
> Number of Observations: 83
> Number of Groups: 14
>  >
> 
> What is happening and what shall I do about it?
> 
> Cheers
> /CG
> 
> -- 
> CG Pettersson, MSci, PhD Stud.
> Swedish University of Agricultural Sciences (SLU)
> Dept. of Crop Production Ecology. Box 7043.
> SE-750 07 UPPSALA, Sweden.
> +46 18 671428, +46 70 3306685
> cg.pettersson at evp.slu.se
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list