Hello, I am work with a linear regression model: y=ax+b with the function of lm. y= observed migration distance of butterflies x= predicted migration distance of butterflies Usually the result will show if the linear term a is significantly different from zero based on the p-value. Now I would like to test if the linear term is significantly different from one. (because I want to know if the regression line (y=ax+b) is significantly from the line with the linear term =1 and the intercept =0) Please kindly advise if it is possible to adjust some default parameters in the function to achieve the goal. Thank you. Elaine [[alternative HTML version deleted]]
Paul Johnson
2013-May-01 02:54 UTC
[R] significantly different from one (not zero) using lm
It is easy to construct your own test. I test against null of 0 first so I can be sure I match the right result from summary.lm. ## get the standard error seofb <- sqrt(diag(vcov(lm1))) ## calculate t. Replace 0 by your null myt <- (coef(lm1) - 0)/seofb mypval <- 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual) ## Note you can pass a vector of different nulls for the coefficients myt <- (coef(lm1) - c(0,1))/seofb We could write this into a function if we wanted to get busy. Not a bad little homework exercise, I think.> dat <- data.frame(x = rnorm(100), y = rnorm(100)) > lm1 <- lm(y ~ x, data = dat) > summary(lm1)Call: lm(formula = y ~ x, data = dat) Residuals: Min 1Q Median 3Q Max -3.0696 -0.5833 0.1351 0.7162 2.3229 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.001499 0.104865 -0.014 0.989 x -0.039324 0.113486 -0.347 0.730 Residual standard error: 1.024 on 98 degrees of freedom Multiple R-squared: 0.001224, Adjusted R-squared: -0.008968 F-statistic: 0.1201 on 1 and 98 DF, p-value: 0.7297> seofb <- sqrt(diag(vcov(lm1))) > myt <- (coef(lm1) - 0)/seofb > mypval <- 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual) > myt(Intercept) x -0.01429604 -0.34650900> mypval(Intercept) x 0.9886229 0.7297031> myt <- (coef(lm1) - 1)/seofb > mypval <- 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual) > myt(Intercept) x -9.550359 -9.158166> mypval(Intercept) x 1.145542e-15 8.126553e-15 On Tue, Apr 30, 2013 at 9:07 PM, Elaine Kuo <elaine.kuo.tw@gmail.com> wrote:> Hello, > > > > I am work with a linear regression model: > > y=ax+b with the function of lm. > > y= observed migration distance of butterflies > > x= predicted migration distance of butterflies > > > > Usually the result will show > > if the linear term a is significantly different from zero based on the > p-value. > > Now I would like to test if the linear term is significantly different from > one. > > (because I want to know if the regression line (y=ax+b) is significantly > from the line with the linear term =1 and the intercept =0) > > > > Please kindly advise if it is possible > > to adjust some default parameters in the function to achieve the goal. > > Thank you. > > > Elaine > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Paul E. Johnson Professor, Political Science Assoc. Director 1541 Lilac Lane, Room 504 Center for Research Methods University of Kansas University of Kansas http://pj.freefaculty.org http://quant.ku.edu [[alternative HTML version deleted]]
Achim Zeileis
2013-May-01 08:32 UTC
[R] significantly different from one (not zero) using lm
On Wed, 1 May 2013, Elaine Kuo wrote:> Hello, > > I am work with a linear regression model: > > y=ax+b with the function of lm. > > y= observed migration distance of butterflies > > x= predicted migration distance of butterflies > > > > Usually the result will show > > if the linear term a is significantly different from zero based on the > p-value. > > Now I would like to test if the linear term is significantly different from > one. > > (because I want to know if the regression line (y=ax+b) is significantly > from the line with the linear term =1 and the intercept =0)In addition to the solutions suggested by Paul and Thomas, you could use linearHypothesis() from the "car" package. A (non-sensical) example using the cars dataset is: m <- lm(dist ~ speed, data = cars) linearHypothesis(m, c("(Intercept) = 0", "speed = 1")) The output is equivalent to the anova() for the offset model that Thomas suggested: m0 <- lm(dist ~ 0 + offset(1 * speed), data = cars) anova(m0, m)> Please kindly advise if it is possible > > to adjust some default parameters in the function to achieve the goal. > > Thank you. > > > Elaine > > [[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. >