[R] Lm function: Error in model.frame.default

Julie julie.novakova at gmail.com
Tue Oct 25 20:22:03 CEST 2011


When I tried dput function, the result was this:

> dput(x)
c(20, 200, 2000, 20000)

> dput(y)
c(0.45, 0.05, 0.5, 0.4, 0, 0.5, 0.4, 0.05, 0.4, 0.25, 0.35, 0.5, 
0.05, 0.4, 0.5, 0.5, 0.5, 0.25, 0.85, 0.5, 0.5, 0.5, 0.25, 0.4, 
0.25, 0.25, 0.4, 0.25, 0.5, 0.15, 0.25, 0.1, 0.25, 0.25, 0.015, 
0.4, 0.5, 0.2, 0.25, 5e-05, 0.5, 0.005, 0.5, 0.25, 0.25, 0.4, 
0.5, 0.4, 0.5, 0.5, 0.5, 0.5, 0.7142857143, 0.5, 0.005, 0.35, 
0.5, 0.35, 0, 0.5, 0.25, 0.25, 1, 0.25, 0.1, 0.25, 0.5, 0.25, 
0.55, NA, 0.25, 0.4, 0.35, 0.35, 0.25, 0, 0.8888888889, 0.5, 
0.25, 0.5, 0.5, 0.5, 0.25, 0.2, 0.4, 0, 0.35, 0.025, 0.4, 0.5, 
0.35, 0.25, 0.3, 0.25, 0.005, 0.5, 0.4, 0.05, 0.5, 0.4, 0.005, 
0.45, 0.4, 0.35, 0.5, 0.005, 0.3, 0.05, 0.25, 0.35, 0.35, 0.75, 
0.5, 0.375, 0.45, 0.1, 0.4, 0.25, 0.25, 0.25, 0.25, 0.5, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.2, 
5e-04, 0.5, 0.5, 0.025, 0.25, 0.25, 0.01, 0.35, 0.15, 0.3, 0.5, 
5e-04, 0.3, 0.4, 0.25, 0.4, 0.25, 0.85, 0.25, 0.375, 0.25, 0.1, 
0.35, 0.05, 0.25, 0.2, 5000, 0.5, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.05, 5e-05, 0.5, 0.6, 0.005, 
0.25, 0.25, 0.0025, 0.4, 0.1, 0.25, 0.5, 0.001, 0.25, 0.4, 0.25, 
0.45, 0.05, 0.6, 0.25, 0.4, 5e-05, 0.05, 0.35, 0.05, 0.15, 0.05, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA)

***

To have the same number of elements, I used the mean of each column to pair
with 20 ... 20 000; but this would affect the p-value, because R does not
know whar there were much more data than just four.
The result is this:


/> summary (lm (d~log(x)))

Call:
lm(formula = d ~ log(x))

Residuals:
        1         3         4 
-0.001108  0.010249 -0.009141 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)  0.39008    0.02591  15.055   0.0422 *
log(x)       0.06184    0.01115   5.547   0.1135  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.01378 on 1 degrees of freedom
  (1 observation deleted due to missingness)
Multiple R-squared: 0.9685,     Adjusted R-squared: 0.937 
F-statistic: 30.77 on 1 and 1 DF,  p-value: 0.1135 

Warning message:
In log(x) : NaNs produced/

***

I tried to handle this by not using just a single number (the mean of the
column), but compose the mean itself in the data:

> d3 <- c(mean(rdiktator20), mean(rDiktator200), mean(rDikt2000),
> mean(rDikt20000))

However, I did not ge any results from it:

> lm (d3~log(x))
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

So there are still NAs blocking the linear model, although I had used the
na.omit function...

--
View this message in context: http://r.789695.n4.nabble.com/Lm-function-Error-in-model-frame-default-tp3933466p3937705.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list