Moffet, Corey
2002-Jan-10 13:46 UTC
[R] Test if beta is different from something other than 0
Is there a function/package that will allow you to test the hypothesis beta1 = x in a simple linear regression, where x is a constant? The AOV tests if beta1 in different from 0 but what if I want to know if beta1 one is different from 1? With best wishes and kind regards I am Sincerely, Corey A. Moffet Instructor Department of Range, Wildlife, and Fisheries Management Mail Stop 2125 Texas Tech University Lubbock, Texas 79409-2125 (806) 742-2843 Voice (806) 742-2280 FAX c.moffet at ttu.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Jan-10 14:19 UTC
[R] Test if beta is different from something other than 0
"Moffet, Corey" <Corey.Moffet at ttu.edu> writes:> Is there a function/package that will allow you to test the hypothesis beta1 > = x in a > simple linear regression, where x is a constant? The AOV tests if beta1 in > different from > 0 but what if I want to know if beta1 one is different from 1?(Slightly unfortunate choice of variable names there.) Say that y are responses and x the *predictor*:> x<-1:10 > y <- x+rnorm(10) > summary(lm(y~x))Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -2.5600 -0.1918 0.2597 0.4870 1.1106 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.3347 0.7225 -0.463 0.655 x 1.0557 0.1164 9.067 1.76e-05 *** --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 1.058 on 8 degrees of freedom Multiple R-Squared: 0.9113, Adjusted R-squared: 0.9002 F-statistic: 82.2 on 1 and 8 DF, p-value: 1.755e-05> summary(lm(y-x~x))Call: lm(formula = y - x ~ x) Residuals: Min 1Q Median 3Q Max -2.5600 -0.1918 0.2597 0.4870 1.1106 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.33475 0.72250 -0.463 0.655 x 0.05572 0.11644 0.478 0.645 Residual standard error: 1.058 on 8 degrees of freedom Multiple R-Squared: 0.02782, Adjusted R-squared: -0.0937 F-statistic: 0.229 on 1 and 8 DF, p-value: 0.6451 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Liaw, Andy
2002-Jan-10 15:10 UTC
[R] Test if beta is different from something other than 0
More generally, I believe linear.hypothesis in the package `car' can be used: linear.hypothesis(lm(y~x), matrix(c(0,1), 1, 2), 1) [I hope this is the right way to call linear.hypothesis?] Andy> -----Original Message----- > From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] > Sent: Thursday, January 10, 2002 9:20 AM > To: Moffet, Corey > Cc: 'r-help at stat.math.ethz.ch' > Subject: Re: [R] Test if beta is different from something other than 0 > > > "Moffet, Corey" <Corey.Moffet at ttu.edu> writes: > > > Is there a function/package that will allow you to test the > hypothesis beta1 > > = x in a > > simple linear regression, where x is a constant? The AOV > tests if beta1 in > > different from > > 0 but what if I want to know if beta1 one is different from 1? > > (Slightly unfortunate choice of variable names there.) > > Say that y are responses and x the *predictor*: > > > x<-1:10 > > y <- x+rnorm(10) > > summary(lm(y~x)) > > Call: > lm(formula = y ~ x) > > Residuals: > Min 1Q Median 3Q Max > -2.5600 -0.1918 0.2597 0.4870 1.1106 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.3347 0.7225 -0.463 0.655 > x 1.0557 0.1164 9.067 1.76e-05 *** > --- > Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > > Residual standard error: 1.058 on 8 degrees of freedom > Multiple R-Squared: 0.9113, Adjusted R-squared: 0.9002 > F-statistic: 82.2 on 1 and 8 DF, p-value: 1.755e-05 > > > summary(lm(y-x~x)) > > Call: > lm(formula = y - x ~ x) > > Residuals: > Min 1Q Median 3Q Max > -2.5600 -0.1918 0.2597 0.4870 1.1106 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.33475 0.72250 -0.463 0.655 > x 0.05572 0.11644 0.478 0.645 > > Residual standard error: 1.058 on 8 degrees of freedom > Multiple R-Squared: 0.02782, Adjusted R-squared: -0.0937 > F-statistic: 0.229 on 1 and 8 DF, p-value: 0.6451 > > > -- > O__ ---- Peter Dalgaard Blegdamsvej 3 > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: > (+45) 35327918 > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: > (+45) 35327907 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.-.-.-.-.- > r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Corey, The linear.hypothesis function in the car package will test any linear hypothesis. But the standard summary output for a linear model gives you the coefficient, its standard error, and the residual df, so why not just compute your own t, and use pt to get the p-value? John At 07:46 AM 1/10/2002 -0600, you wrote:>Is there a function/package that will allow you to test the hypothesis beta1 >= x in a >simple linear regression, where x is a constant? The AOV tests if beta1 in >different from >0 but what if I want to know if beta1 one is different from 1?----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Warnes, Gregory R
2002-Jan-10 17:31 UTC
[R] Test if beta is different from something other than 0
> -----Original Message-----> From: Moffet, Corey [mailto:Corey.Moffet at ttu.edu] > Sent: Thursday, January 10, 2002 8:47 AM > To: 'r-help at stat.math.ethz.ch' > Subject: [R] Test if beta is different from something other than 0 > > > Is there a function/package that will allow you to test the > hypothesis beta1 > = x in a > simple linear regression, where x is a constant? I've written a funcgion 'glh.test' for testing general linear hypotheses. For this case, you can use glh.test as: > x <- rnorm(100) > y <- rnorm(100,x+1) > reg <- lm(y~x) > # test the hypothesis that (b1*0, b1*1) == 1 > glh.test( reg, c( 0, 1), c(1) ) Test of General Linear Hypothesis Call: glh.test(reg = reg, cm = c(0, 1), d = c(1)) F = 2.331, df1 = 1, df2 = 98, p-value = 0.1300 I'm pasting the function and the documentation below. 'glh.test' will be part of the next release of the gregmisc library, which will be out as soon as I can get it through the publication review process. -Greg ##################### start of glh.test.R ############################ # $Id: glh.test.R,v 1.3 2001/12/19 20:05:27 warneg Exp $ # # $Log: glh.test.R,v $ # Revision 1.3 2001/12/19 20:05:27 warneg # # - Removed extra element of return object. # # Revision 1.2 2001/12/18 21:34:25 warneg # - Modified to work correctly when obj is of class 'aov' by specifying # summary.lm instead of summary. This ensures that the summary object # has the fields we need. # # - Moved detailed reporting of results from 'print' to 'summary' # function and added a simpler report to 'print' # # Revision 1.1 2001/12/18 00:43:23 warneg # # Initial checkin. # # glh.test <- function( reg, cm, d=rep(0, nrow(cm)) ) { if( !is.matrix(cm) && !is.data.frame(cm) ) cm <- matrix(cm, nrow=1) if ( !( "lm" %in% class(reg) ) ) stop("Only defined for lm,glm objects") bhat <- summary.lm(reg)$coefficients[,1,drop=F] XpX <- summary.lm(reg)$cov.unscaled df <- reg$df.residual msr <- summary.lm(reg)$sigma # == SSE / (n-p) r <- nrow(cm) if ( ncol(cm) != length(bhat) ) stop( paste( "\n Dimension of ", deparse( substitute( cm ) ), ": ", o paste( dim(cm), collapse="x" ), ", not compatible with no of parameters in ", deparse( substitute( reg ) ), ": ", length(bhat), sep="" ) ) # -1 # (Cb - d)' ( C (X'X) C' ) (Cb - d) / r # F = --------------------------------------- # SSE / (n-p) # Fstat <- t(cm %*% bhat - d) %*% solve((cm %*% XpX %*% t(cm))) %*% (cm %*% bhat - d) / r / msr^2 p <- 1-pf(Fstat,r,df) retval <- list() retval$call <- match.call() retval$statistic <- c(F=Fstat) retval$parameter <- c(df1=r,df2=df) retval$p.value <- p retval$conf.int <- NULL retval$estimate <- cm%*%bhat retval$null.value <- d retval$method <- "Test of General Linear Hypothesis" retval$data.name <- deparse(substitute(reg)) retval$matrix <- cm colnames(retval$matrix) <- names(reg$coef) class(retval) <- c("glh.test","htest") retval } print.glh.test <- function(x, digits = 4 ) { cat("\n") cat("\t",x$method, prefix = "\t") cat("\n") cat("Call:\n") print(x$call) if (!is.null(x$statistic)) cat(names(x$statistic), " = ", format(round(x$statistic, 4)), ", ", sep = "") if (!is.null(x$parameter)) cat(paste(names(x$parameter), " = ", format(round(x$parameter, 3)), ",", sep = ""), "") cat("p-value =", format.pval(x$p.value, digits = digits), "\n") cat("\n") } summary.glh.test <- function(x, digits = 4 ) { cat("\n") cat("\t",x$method, prefix = "\t") cat("\n") cat("Regression: ", x$data.name, "\n") cat("\n") cat("Null Hypothesis: C %*% Beta-hat = d \n") cat("\n") cat("C matrix: \n") print(x$matrix, digits=digits) cat("\n") cat("d vector: \n") print(x$null.value, digits=digits) cat("\n") cat("C %*% Beta-hat: \n") print(c(x$estimate)) cat("\n") if (!is.null(x$statistic)) cat(names(x$statistic), " = ", format(round(x$statistic, 4)), ", ", sep = "") if (!is.null(x$parameter)) cat(paste(names(x$parameter), " = ", format(round(x$parameter, 3)), ",", sep = ""), "") cat("p-value =", format.pval(x$p.value, digits = digits), "\n") cat("\n") } ##################### end of glh.test.R ########################### ##################### start of glh.test documentation ########################### glh.test package:gregmisc R Documentation Test a General Linear Hypothesis for a Regression Model Description: Test, print, or summarize a general linear hypothesis for a regression model Usage: glh.test(reg, cm, d=rep(0, nrow(cm)) ) print.glh.test(x, digits=4) summary.glh.test(x, digits=4) Arguments: reg: Regression model cm: matrix . Each row specifies a linear combination of the coefficients d: vector specifying the null hypothis values for each linear combination x: glh.test object digits: number of digits. Details: Test the general lineary hypothesis C %*% beta_hat == d for the regression model `reg'. The test statistic is obtained from the formula: F = (C Beta-hat - d)' ( C (X'X)^-1 C' ) (C Beta-hat - d) / r / ( SSE / (n-p) ) Under the null hypothesis, f will follow a F-distribution with r and n-p degrees of freedom. Value: Object of class `c("glh.test","htest")' with elements: call : Function call that created the object statistic : F statistic parameter: vector containing the numerator (r) and denominator (n-p) degrees of freedom p.value: p-value estimate: computed estimate for each row of `cm' null.value: d method: description of the method data.name: name of the model given for `reg' matrix: matrix specifying the general linear hypotheis (`cm') Author(s): Gregory R. Warnes gregory_r_warnes\@groton.pfizer.com References: R.H. Myers, Classical and Modern Regression with Applications, 2nd Ed, 1990, p. 105 See Also: `contrast.lm', `estimable', `contrast', `contrasts' Examples: # fit a simple model y _ rnorm(100) x _ cut(rnorm(100, mean=y, sd=0.25),c(-4,-1.5,0,1.5,4)) reg _ lm(y ~ x) summary(reg) # test both group 1 = group 2 and group 3 = group 4 C <- rbind( c(0,-1,0,0), c(0,0,-1,1) ) ret <- glh.test(reg, C) ret # same as 'print(ret) ' summary(ret) ##################### end of glh.test documentation ########################### LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._