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 <julie.novak...@gmail.com> 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. > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.