[R] Problems with abline adding regression line to a graph
CG Pettersson
cg.pettersson at evp.slu.se
Thu Nov 3 16:03:05 CET 2005
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.
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
More information about the R-help
mailing list