Hello, Thanks. But the parameter offset is new to me. Please kindly explain why setting offset to x will give a significant test of whether the slope coefficient is different from one. (I checked the ?lm but still do not understand it well)
Thanks again Elaine On Wed, May 1, 2013 at 11:12 AM, Thomas Lumley <tlum...@uw.edu> wrote: > Or use an offset > > lm( y ~ x+offset(x), data = dat) > > The offset gives x a coefficient of 1, so the coefficient of x in this > model is the difference between the coefficient of x in the model without > an offset and 1 -- the thing you want. > > -thomas > > > On Wed, May 1, 2013 at 2:54 PM, Paul Johnson <pauljoh...@gmail.com> wrote: > >> 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...@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]] >> >> ______________________________________________ >> 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. >> > > > > -- > Thomas Lumley > Professor of Biostatistics > University of Auckland > [[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.