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

R. Michael Weylandt michael.weylandt at gmail.com
Mon Oct 31 16:31:32 CET 2011


I don't know if you've gotten any follow up, but here are some quick reactions:

1) You make reference to the columns of y but your dput(y) does not
provide columns,

2) It's still not clear to me what all this data actually means? Do
you have multiple observations of the dependent variable corresponding
to each level of x? If so, a linear model probably isn't the best way
to approach the problem.

3) You give this code; d3 <- c(mean(rdiktator20), mean(rDiktator200),
mean(rDikt2000), mean(rDikt20000)) but you don't make any of that data
available to us.

If pressed, I'd guess that the reason this seems hard to do in R is
that it's not good statistical practice and that you should take a
moment to make sure it's really what you want to do given your data,
assuming I understood it properly above.

Michael

On Tue, Oct 25, 2011 at 2:22 PM, Julie <julie.novakova at gmail.com> wrote:
> 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.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list