Re: [R] significantly different from one (not zero) using lm
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.0140.989 x -0.039324 0.113486 -0.3470.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.
Re: [R] significantly different from one (not zero) using lm
Parameters are different from functions, and offset is a function. Kindly read the help for that function and the references given there. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Elaine Kuo elaine.kuo...@gmail.com wrote: 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.0140.989 x -0.039324 0.113486 -0.3470.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
Re: [R] significantly different from one (not zero) using lm
The offset(x) term means to include x (or whatever is in the parentheses) into the model as is, without computing a slope for that term. You could also include offset( 1 * x ) instead which might make this a bit more explicit (but would not actually make any difference). Since x by itself is also in the model with a computed slope that slope will measure the difference from 1. So the model is fitting y = b0 + b1 * x + 1 * x + e with b0 and b1 being computed, if we factor that then it is y = b0 + (b1 + 1) * x + e, so the estimate of b1 is how much the overall slope of x differs from 1 and the standard test on b1 now does what you want. On Sat, May 4, 2013 at 5:35 AM, Elaine Kuo elaine.kuo...@gmail.com wrote: 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.0140.989 x -0.039324 0.113486 -0.3470.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]] __
Re: [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@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.
[R] significantly different from one (not zero) using lm
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.
Re: [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.0140.989 x -0.039324 0.113486 -0.3470.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.
Re: [R] significantly different from one (not zero) using lm
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.0140.989 x -0.039324 0.113486 -0.3470.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.