Lm function: Error in model.frame.default

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Lm function: Error in model.frame.default

Julie
Hello,
I am trying to get a linear model of y ~ log(x).
> lm (y~log(x))
However, I always get an error report:
Error in model.frame.default(formula = y ~ log(x), drop.unused.levels = TRUE) :
  variable lengths differ (found for 'log(x)')


Here was my y:
> y
  [1]    0.4500000    0.0500000    0.5000000    0.4000000    0.0000000    0.5000000    0.4000000
  [8]    0.0500000    0.4000000    0.2500000    0.3500000    0.5000000    0.0500000    0.4000000
 [15]    0.5000000    0.5000000    0.5000000    0.2500000    0.8500000    0.5000000    0.5000000
 [22]    0.5000000    0.2500000    0.4000000    0.2500000    0.2500000    0.4000000    0.2500000
 [29]    0.5000000    0.1500000    0.2500000    0.1000000    0.2500000    0.2500000    0.0150000
 [36]    0.4000000    0.5000000    0.2000000    0.2500000    0.0000500    0.5000000    0.0050000
 [43]    0.5000000    0.2500000    0.2500000    0.4000000    0.5000000    0.4000000    0.5000000
 [50]    0.5000000    0.5000000    0.5000000    0.7142857    0.5000000    0.0050000    0.3500000
 [57]    0.5000000    0.3500000    0.0000000    0.5000000    0.2500000    0.2500000    1.0000000
 [64]    0.2500000    0.1000000    0.2500000    0.5000000    0.2500000    0.5500000           NA
 [71]    0.2500000    0.4000000    0.3500000    0.3500000    0.2500000    0.0000000    0.8888889
 [78]    0.5000000    0.2500000    0.5000000    0.5000000    0.5000000    0.2500000    0.2000000
 [85]    0.4000000    0.0000000    0.3500000    0.0250000    0.4000000    0.5000000    0.3500000
 [92]    0.2500000    0.3000000    0.2500000    0.0050000    0.5000000    0.4000000    0.0500000
 [99]    0.5000000    0.4000000    0.0050000    0.4500000    0.4000000    0.3500000    0.5000000
[106]    0.0050000    0.3000000    0.0500000    0.2500000    0.3500000    0.3500000    0.7500000
[113]    0.5000000    0.3750000    0.4500000    0.1000000    0.4000000    0.2500000    0.2500000
[120]    0.2500000    0.2500000    0.5000000           NA           NA           NA           NA
[127]           NA           NA           NA           NA           NA           NA           NA
[134]           NA           NA           NA           NA           NA           NA           NA
[141]           NA           NA           NA           NA           NA           NA           NA
[148]           NA           NA           NA           NA           NA           NA           NA
[155]           NA           NA           NA           NA           NA           NA           NA
[162]           NA           NA           NA           NA           NA           NA           NA
[169]           NA           NA           NA           NA           NA           NA           NA
[176]           NA           NA           NA           NA           NA           NA           NA
[183]           NA           NA           NA           NA    0.2000000    0.0005000    0.5000000
[190]    0.5000000    0.0250000    0.2500000    0.2500000    0.0100000    0.3500000    0.1500000
[197]    0.3000000    0.5000000    0.0005000    0.3000000    0.4000000    0.2500000    0.4000000
[204]    0.2500000    0.8500000    0.2500000    0.3750000    0.2500000    0.1000000    0.3500000
[211]    0.0500000    0.2500000    0.2000000 5000.0000000    0.5000000           NA           NA
[218]           NA           NA           NA           NA           NA           NA           NA
[225]           NA           NA           NA           NA           NA           NA           NA
[232]           NA           NA           NA           NA           NA           NA           NA
[239]           NA           NA           NA           NA           NA           NA           NA
[246]           NA           NA           NA           NA           NA           NA           NA
[253]           NA           NA           NA           NA           NA           NA           NA
[260]           NA           NA           NA           NA           NA           NA           NA
[267]           NA           NA           NA           NA           NA           NA           NA
[274]           NA           NA           NA           NA           NA           NA    0.0500000
[281]    0.0000500    0.5000000    0.6000000    0.0050000    0.2500000    0.2500000    0.0025000
[288]    0.4000000    0.1000000    0.2500000    0.5000000    0.0010000    0.2500000    0.4000000
[295]    0.2500000    0.4500000    0.0500000    0.6000000    0.2500000    0.4000000    0.0000500
[302]    0.0500000    0.3500000    0.0500000    0.1500000    0.0500000           NA           NA
[309]           NA           NA           NA           NA           NA           NA           NA
[316]           NA           NA           NA           NA           NA           NA           NA
[323]           NA           NA           NA           NA           NA           NA           NA
[330]           NA           NA           NA           NA           NA           NA           NA
[337]           NA           NA           NA           NA           NA           NA           NA
[344]           NA           NA           NA           NA           NA           NA           NA
[351]           NA           NA           NA           NA           NA           NA           NA
[358]           NA           NA           NA           NA           NA           NA           NA
[365]           NA           NA           NA           NA           NA           NA           NA
[372]           NA

Here was my x:
> x
[1]    20   200  2000 20000

I deleted [372] from y, because I thought it could help, the length of y would be the same. It did not change the error report.
I did as.data.frame with both y and x and this did not help either. I am not sure what I should do now. Thank you for help!



Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Michael Weylandt
You are trying to regress ~372 observations of the dependent against
~4 observations of the independent variable. Ask yourself again if
this makes sense.

A further hint might be given by this

y = rnorm(5); x = y[1:4]
lm(y~x)

Michael

On Mon, Oct 24, 2011 at 11:13 AM, Julie <[hidden email]> wrote:

> Hello,
> I am trying to get a linear model of y ~ log(x).
> *> lm (y~log(x))*
> However, I always get an error report:
> /Error in model.frame.default(formula = y ~ log(x), drop.unused.levels =
> TRUE) :
>  variable lengths differ (found for 'log(x)')/
>
> *Here was my y:*
>> y
>  [1]    0.4500000    0.0500000    0.5000000    0.4000000    0.0000000
> 0.5000000    0.4000000
>  [8]    0.0500000    0.4000000    0.2500000    0.3500000    0.5000000
> 0.0500000    0.4000000
>  [15]    0.5000000    0.5000000    0.5000000    0.2500000    0.8500000
> 0.5000000    0.5000000
>  [22]    0.5000000    0.2500000    0.4000000    0.2500000    0.2500000
> 0.4000000    0.2500000
>  [29]    0.5000000    0.1500000    0.2500000    0.1000000    0.2500000
> 0.2500000    0.0150000
>  [36]    0.4000000    0.5000000    0.2000000    0.2500000    0.0000500
> 0.5000000    0.0050000
>  [43]    0.5000000    0.2500000    0.2500000    0.4000000    0.5000000
> 0.4000000    0.5000000
>  [50]    0.5000000    0.5000000    0.5000000    0.7142857    0.5000000
> 0.0050000    0.3500000
>  [57]    0.5000000    0.3500000    0.0000000    0.5000000    0.2500000
> 0.2500000    1.0000000
>  [64]    0.2500000    0.1000000    0.2500000    0.5000000    0.2500000
> 0.5500000           NA
>  [71]    0.2500000    0.4000000    0.3500000    0.3500000    0.2500000
> 0.0000000    0.8888889
>  [78]    0.5000000    0.2500000    0.5000000    0.5000000    0.5000000
> 0.2500000    0.2000000
>  [85]    0.4000000    0.0000000    0.3500000    0.0250000    0.4000000
> 0.5000000    0.3500000
>  [92]    0.2500000    0.3000000    0.2500000    0.0050000    0.5000000
> 0.4000000    0.0500000
>  [99]    0.5000000    0.4000000    0.0050000    0.4500000    0.4000000
> 0.3500000    0.5000000
> [106]    0.0050000    0.3000000    0.0500000    0.2500000    0.3500000
> 0.3500000    0.7500000
> [113]    0.5000000    0.3750000    0.4500000    0.1000000    0.4000000
> 0.2500000    0.2500000
> [120]    0.2500000    0.2500000    0.5000000           NA           NA
> NA           NA
> [127]           NA           NA           NA           NA           NA
> NA           NA
> [134]           NA           NA           NA           NA           NA
> NA           NA
> [141]           NA           NA           NA           NA           NA
> NA           NA
> [148]           NA           NA           NA           NA           NA
> NA           NA
> [155]           NA           NA           NA           NA           NA
> NA           NA
> [162]           NA           NA           NA           NA           NA
> NA           NA
> [169]           NA           NA           NA           NA           NA
> NA           NA
> [176]           NA           NA           NA           NA           NA
> NA           NA
> [183]           NA           NA           NA           NA    0.2000000
> 0.0005000    0.5000000
> [190]    0.5000000    0.0250000    0.2500000    0.2500000    0.0100000
> 0.3500000    0.1500000
> [197]    0.3000000    0.5000000    0.0005000    0.3000000    0.4000000
> 0.2500000    0.4000000
> [204]    0.2500000    0.8500000    0.2500000    0.3750000    0.2500000
> 0.1000000    0.3500000
> [211]    0.0500000    0.2500000    0.2000000 5000.0000000    0.5000000
> NA           NA
> [218]           NA           NA           NA           NA           NA
> NA           NA
> [225]           NA           NA           NA           NA           NA
> NA           NA
> [232]           NA           NA           NA           NA           NA
> NA           NA
> [239]           NA           NA           NA           NA           NA
> NA           NA
> [246]           NA           NA           NA           NA           NA
> NA           NA
> [253]           NA           NA           NA           NA           NA
> NA           NA
> [260]           NA           NA           NA           NA           NA
> NA           NA
> [267]           NA           NA           NA           NA           NA
> NA           NA
> [274]           NA           NA           NA           NA           NA
> NA    0.0500000
> [281]    0.0000500    0.5000000    0.6000000    0.0050000    0.2500000
> 0.2500000    0.0025000
> [288]    0.4000000    0.1000000    0.2500000    0.5000000    0.0010000
> 0.2500000    0.4000000
> [295]    0.2500000    0.4500000    0.0500000    0.6000000    0.2500000
> 0.4000000    0.0000500
> [302]    0.0500000    0.3500000    0.0500000    0.1500000    0.0500000
> NA           NA
> [309]           NA           NA           NA           NA           NA
> NA           NA
> [316]           NA           NA           NA           NA           NA
> NA           NA
> [323]           NA           NA           NA           NA           NA
> NA           NA
> [330]           NA           NA           NA           NA           NA
> NA           NA
> [337]           NA           NA           NA           NA           NA
> NA           NA
> [344]           NA           NA           NA           NA           NA
> NA           NA
> [351]           NA           NA           NA           NA           NA
> NA           NA
> [358]           NA           NA           NA           NA           NA
> NA           NA
> [365]           NA           NA           NA           NA           NA
> NA           NA
> [372]           NA
>
> *Here was my x:*
>> x
> [1]    20   200  2000 20000
>
> I deleted [372] from y, because I thought it could help, the length of y
> would be the same. It did not change the error report.
> I did as.data.frame with both y and x and this did not help either. I am not
> sure what I should do now. Thank you for help!
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Lm-function-Error-in-model-frame-default-tp3933466p3933466.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Julie
The variable y is made of four columns, each paired to 20, 200, 2000 or 20 000.
> y <- c(rdiktator20, rDiktator200, rDikt2000, rDikt20000)

So I guess the problem is in the fact that I did not specify it correctly, is it so? How can I tell R properly that one part of y matches to one part of x?

The result I am looking for looks like this in Calc, however, I need to do it in R because it can tell me more:

The y axis shows how big rdiktator20, rDiktator200, rDikt2000 or rDikt20000 is. The x axis shows the logarithm of 20, 200, 2000 and 20 000.
Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Jeff Newmiller
In reply to this post by Julie
X and y must have the same number of elements, and NA values must be removed (?na.omit)
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<[hidden email]> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

Julie <[hidden email]> wrote:

Hello,
I am trying to get a linear model of y ~ log(x).
*> lm (y~log(x))*
However, I always get an error report:
/Error in model.frame.default(formula = y ~ log(x), drop.unused.levels =
TRUE) :
variable lengths differ (found for 'log(x)')/

*Here was my y:*
> y
[1] 0.4500000 0.0500000 0.5000000 0.4000000 0.0000000
0.5000000 0.4000000
[8] 0.0500000 0.4000000 0.2500000 0.3500000 0.5000000
0.0500000 0.4000000
[15] 0.5000000 0.5000000 0.5000000 0.2500000 0.8500000
0.5000000 0.5000000
[22] 0.5000000 0.2500000 0.4000000 0.2500000 0.2500000
0.4000000 0.2500000
[29] 0.5000000 0.1500000 0.2500000 0.1000000 0.2500000
0.2500000 0.0150000
[36] 0.4000000 0.5000000 0.2000000 0.2500000 0.0000500
0.5000000 0.0050000
[43] 0.5000000 0.2500000 0.2500000 0.4000000 0.5000000
0.4000000 0.5000000
[50] 0.5000000 0.5000000 0.5000000 0.7142857 0.5000000
0.0050000 0.3500000
[57] 0.5000000 0.3500000 0.0000000 0.5000000 0.2500000
0.2500000 1.0000000
[64] 0.2500000 0.1000000 0.2500000 0.5000000 0.2500000
0.5500000 NA
[71] 0.2500000 0.4000000 0.3500000 0.3500000 0.2500000
0.0000000 0.8888889
[78] 0.5000000 0.2500000 0.5000000 0.5000000 0.5000000
0.2500000 0.2000000
[85] 0.4000000 0.0000000 0.3500000 0.0250000 0.4000000
0.5000000 0.3500000
[92] 0.2500000 0.3000000 0.2500000 0.0050000 0.5000000
0.4000000 0.0500000
[99] 0.5000000 0.4000000 0.0050000 0.4500000 0.4000000
0.3500000 0.5000000
[106] 0.0050000 0.3000000 0.0500000 0.2500000 0.3500000
0.3500000 0.7500000
[113] 0.5000000 0.3750000 0.4500000 0.1000000 0.4000000
0.2500000 0.2500000
[120] 0.2500000 0.2500000 0.5000000 NA NA
NA NA
[127] NA NA NA NA NA
NA NA
[134] NA NA NA NA NA
NA NA
[141] NA NA NA NA NA
NA NA
[148] NA NA NA NA NA
NA NA
[155] NA NA NA NA NA
NA NA
[162] NA NA NA NA NA
NA NA
[169] NA NA NA NA NA
NA NA
[176] NA NA NA NA NA
NA NA
[183] NA NA NA NA 0.2000000
0.0005000 0.5000000
[190] 0.5000000 0.0250000 0.2500000 0.2500000 0.0100000
0.3500000 0.1500000
[197] 0.3000000 0.5000000 0.0005000 0.3000000 0.4000000
0.2500000 0.4000000
[204] 0.2500000 0.8500000 0.2500000 0.3750000 0.2500000
0.1000000 0.3500000
[211] 0.0500000 0.2500000 0.2000000 5000.0000000 0.5000000
NA NA
[218] NA NA NA NA NA
NA NA
[225] NA NA NA NA NA
NA NA
[232] NA NA NA NA NA
NA NA
[239] NA NA NA NA NA
NA NA
[246] NA NA NA NA NA
NA NA
[253] NA NA NA NA NA
NA NA
[260] NA NA NA NA NA
NA NA
[267] NA NA NA NA NA
NA NA
[274] NA NA NA NA NA
NA 0.0500000
[281] 0.0000500 0.5000000 0.6000000 0.0050000 0.2500000
0.2500000 0.0025000
[288] 0.4000000 0.1000000 0.2500000 0.5000000 0.0010000
0.2500000 0.4000000
[295] 0.2500000 0.4500000 0.0500000 0.6000000 0.2500000
0.4000000 0.0000500
[302] 0.0500000 0.3500000 0.0500000 0.1500000 0.0500000
NA NA
[309] NA NA NA NA NA
NA NA
[316] NA NA NA NA NA
NA NA
[323] NA NA NA NA NA
NA NA
[330] NA NA NA NA NA
NA NA
[337] NA NA NA NA NA
NA NA
[344] NA NA NA NA NA
NA NA
[351] NA NA NA NA NA
NA NA
[358] NA NA NA NA NA
NA NA
[365] NA NA NA NA NA
NA NA
[372] NA

*Here was my x:*
> x
[1] 20 200 2000 20000

I deleted [372] from y, because I thought it could help, the length of y
would be the same. It did not change the error report.
I did as.data.frame with both y and x and this did not help either. I am not
sure what I should do now. Thank you for help!





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

_____________________________________________

[hidden email] 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.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Michael Weylandt
In reply to this post by Julie
Could you dput() the structure of x and y: I'm having trouble
visualizing how your data is set up.

Michael

On Mon, Oct 24, 2011 at 12:07 PM, Julie <[hidden email]> wrote:

> The variable y is made of four columns, each paired to 20, 200, 2000 or 20
> 000.
>> y <- c(rdiktator20, rDiktator200, rDikt2000, rDikt20000)
>
> So I guess the problem is in the fact that I did not specify it correctly,
> is it so? How can I tell R properly that one part of y matches to one part
> of x?
>
> The result I am looking for looks like this in Calc, however, I need to do
> it in R because it can tell me more:
> http://r.789695.n4.nabble.com/file/n3933663/allfour.png
> The y axis shows how big rdiktator20, rDiktator200, rDikt2000 or rDikt20000
> is. The x axis shows the logarithm of 20, 200, 2000 and 20 000.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Lm-function-Error-in-model-frame-default-tp3933466p3933663.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Julie
In reply to this post by Jeff Newmiller
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...
Reply | Threaded
Open this post in threaded view
|

Re: Lm function: Error in model.frame.default

Michael Weylandt
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.