Hi all, I wrote a r program as below: x <- 1:10 y <- c(3,3,3,3,3,3,3,3,3,3) fit <- lm(log(y) ~ x) summary(fit) And I expect to get some error message from R, because "y" is constant. But, I got the message as below:> summary(fit)Call: lm(formula = log(y) ~ x) Residuals: Min 1Q Median 3Q Max -6.802e-17 -3.933e-17 -1.063e-17 1.807e-17 1.530e-16 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.099e+00 4.569e-17 2.404e+16 <2e-16 *** x -1.275e-17 7.364e-18 -1.732e+00 0.122 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 6.688e-17 on 8 degrees of freedom Multiple R-squared: 0.5794, Adjusted R-squared: 0.5269 F-statistic: 11.02 on 1 and 8 DF, p-value: 0.01054 How could this be possible? Did I missing something in my R code? Best, Miles -- ------------------ Miles Yang Mobile:+61-411-985-538 E-mail:miles2yang@gmail.com ------------------ [[alternative HTML version deleted]]
What exactly is it that's worrying you? It's a problematic regression for a few reasons, but ultimately it seems pretty ok, though I'd be ever so slightly worried about the R^2 value being misinterpreted. Michael On Mon, Nov 14, 2011 at 10:49 PM, Miles Yang <miles2yang at gmail.com> wrote:> Hi all, > I wrote a r program as below: > > x <- 1:10 > y <- c(3,3,3,3,3,3,3,3,3,3) > > fit <- lm(log(y) ~ x) > summary(fit) > > And I expect to get some error message from R, because "y" is constant. > But, I got the message as below: > >> summary(fit) > > Call: > lm(formula = log(y) ~ x) > > Residuals: > ? ? ? Min ? ? ? ? 1Q ? ? Median ? ? ? ? 3Q ? ? ? ?Max > -6.802e-17 -3.933e-17 -1.063e-17 ?1.807e-17 ?1.530e-16 > > Coefficients: > ? ? ? ? ? ? ?Estimate Std. Error ? ?t value Pr(>|t|) > (Intercept) ?1.099e+00 ?4.569e-17 ?2.404e+16 ? <2e-16 *** > x ? ? ? ? ? -1.275e-17 ?7.364e-18 -1.732e+00 ? ?0.122 > --- > Signif. codes: ?0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 6.688e-17 on 8 degrees of freedom > Multiple R-squared: 0.5794, Adjusted R-squared: 0.5269 > F-statistic: 11.02 on 1 and 8 DF, ?p-value: 0.01054 > > How could this be possible? > Did I missing something in my R code? > > Best, > Miles > -- > ?????????????????? > Miles Yang > Mobile?+61-411-985-538 > E-mail?miles2yang at gmail.com > ?????????????????? > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > 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. > >
On Nov 14, 2011, at 10:49 PM, Miles Yang wrote:> Hi all, > I wrote a r program as below: > > x <- 1:10 > y <- c(3,3,3,3,3,3,3,3,3,3) > > fit <- lm(log(y) ~ x) > summary(fit) > > And I expect to get some error message from R, because "y" is > constant. > But, I got the message as below:You are asking R to tell you if the mean of the log of 3 was different than 0. It is. -- David.> >> summary(fit) > > Call: > lm(formula = log(y) ~ x) > > Residuals: > Min 1Q Median 3Q Max > -6.802e-17 -3.933e-17 -1.063e-17 1.807e-17 1.530e-16 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 1.099e+00 4.569e-17 2.404e+16 <2e-16 *** > x -1.275e-17 7.364e-18 -1.732e+00 0.122 > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 6.688e-17 on 8 degrees of freedom > Multiple R-squared: 0.5794, Adjusted R-squared: 0.5269 > F-statistic: 11.02 on 1 and 8 DF, p-value: 0.01054 > > How could this be possible? > Did I missing something in my R code? > > Best, > Miles > -- > ?????????????????? > Miles Yang > Mobile?+61-411-985-538 > E-mail?miles2yang at gmail.com > ?????????????????? > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Dear Miles, Within rounding error, you got the right intercept, log(3); slope, 0; residuals, all 0; residual standard error, 0; and standard errors of the intercept and slope, both 0. The R^2 should have been undefined (i.e., 0/0), but dividing one number that's 0 within rounding error by another gives a wild result. Likewise for the omnibus F and t-test for the slope. The moral: don't expect floating-point arithmetic on a computer to be perfectly precise. I hope this helps, John -------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Miles Yang > Sent: November-14-11 10:49 PM > To: r-help-request at r-project.org; r-help at r-project.org > Subject: [R] Question about linear regression in R > > Hi all, > I wrote a r program as below: > > x <- 1:10 > y <- c(3,3,3,3,3,3,3,3,3,3) > > fit <- lm(log(y) ~ x) > summary(fit) > > And I expect to get some error message from R, because "y" is constant. > But, I got the message as below: > > > summary(fit) > > Call: > lm(formula = log(y) ~ x) > > Residuals: > Min 1Q Median 3Q Max > -6.802e-17 -3.933e-17 -1.063e-17 1.807e-17 1.530e-16 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 1.099e+00 4.569e-17 2.404e+16 <2e-16 *** > x -1.275e-17 7.364e-18 -1.732e+00 0.122 > --- > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Residual standard error: 6.688e-17 on 8 degrees of freedom Multiple R- > squared: 0.5794, Adjusted R-squared: 0.5269 > F-statistic: 11.02 on 1 and 8 DF, p-value: 0.01054 > > How could this be possible? > Did I missing something in my R code? > > Best, > Miles > -- > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o<Miles Yang > Mobileo<+61-411-985-538 > E-mailo<miles2yang at gmail.com > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > o< > [[alternative HTML version deleted]]