test option for linearHypothesis in library(car) include "Chisq" and "F". I prefer a simple t-test so that I can retrieve the standard error. Any options other than linearHypothesis to test the linear hypothesis (with 1 restriction/degree of freedom)? > summary(ols1) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.20013 0.09199 -2.176 0.0298 * age 0.04054 0.01721 2.355 0.0187 * suburb 0.01911 0.05838 0.327 0.7435 smcity -0.29969 0.19175 -1.563 0.1184 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > linearHypothesis(ols1,"suburb") Linear hypothesis test Hypothesis: suburb = 0 Model 1: restricted model Model 2: polideo ~ age + suburb + smcity Res.Df RSS Df Sum of Sq F Pr(>F) 1 888 650.10 2 887 650.02 1 0.078534 0.1072 0.7435 [[alternative HTML version deleted]]
But the second column in coef(summary(ols1)) gives you the SE, so why not use that? Otherwise, you may want to look into the 'multcomp' package and its glht() function. Best, Wolfgang> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Steven > Yen > Sent: Tuesday, June 28, 2016 18:27 > To: R-help > Subject: [R] t-test for regression estimate > > test option for linearHypothesis in library(car) include "Chisq" and > "F". I prefer a simple t-test so that I can retrieve the standard error. > Any options other than linearHypothesis to test the linear hypothesis > (with 1 restriction/degree of freedom)? > > > summary(ols1) > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.20013 0.09199 -2.176 0.0298 * > age 0.04054 0.01721 2.355 0.0187 * > suburb 0.01911 0.05838 0.327 0.7435 > smcity -0.29969 0.19175 -1.563 0.1184 > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > > linearHypothesis(ols1,"suburb") > Linear hypothesis test > > Hypothesis: > suburb = 0 > > Model 1: restricted model > Model 2: polideo ~ age + suburb + smcity > > Res.Df RSS Df Sum of Sq F Pr(>F) > 1 888 650.10 > 2 887 650.02 1 0.078534 0.1072 0.7435
Dear Steven, The reason that linearHypothesis() computes a Wald F or chisquare test rather than a t or z test is that the (numerator) df for the linear hypothesis need not be 1. In your case (as has been pointed out) you can get the coefficient standard error directly from the model summary. More generally, with some work, you could solve for the the SE for a 1 df linear hypothesis in terms of the value of the linear function of coefficients and the F or chisquare. That said, I'm not sure why you want to do this. I hope this helps, John ----------------------------- John Fox, Professor McMaster University Hamilton, Ontario Canada L8S 4M4 Web: socserv.mcmaster.ca/jfox> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Steven Yen > Sent: June 28, 2016 9:27 AM > To: R-help <r-help at r-project.org> > Subject: [R] t-test for regression estimate > > test option for linearHypothesis in library(car) include "Chisq" and "F". I prefer > a simple t-test so that I can retrieve the standard error. > Any options other than linearHypothesis to test the linear hypothesis (with 1 > restriction/degree of freedom)? > > > summary(ols1) > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) -0.20013 0.09199 -2.176 0.0298 * > age 0.04054 0.01721 2.355 0.0187 * > suburb 0.01911 0.05838 0.327 0.7435 > smcity -0.29969 0.19175 -1.563 0.1184 > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > > linearHypothesis(ols1,"suburb") > Linear hypothesis test > > Hypothesis: > suburb = 0 > > Model 1: restricted model > Model 2: polideo ~ age + suburb + smcity > > Res.Df RSS Df Sum of Sq F Pr(>F) > 1 888 650.10 > 2 887 650.02 1 0.078534 0.1072 0.7435 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Thanks John. Reason is I am doing linear transformations of many coefficients (e.g., bi / scalar). Of course I can uncover the t-statistic from the F statistic and then the standard error. Simply scaling the estimated coefficients I can also transform the standard errors. I have since found deltaMethod from library "car" useful. Its just that, if linearHypothesis had provide the standard errors and t-statistics then the operation would have been easier, with a one-line command for each coefficient. Thank you again. On 6/28/2016 6:28 PM, Fox, John wrote:> Dear Steven, > > The reason that linearHypothesis() computes a Wald F or chisquare test rather than a t or z test is that the (numerator) df for the linear hypothesis need not be 1. > > In your case (as has been pointed out) you can get the coefficient standard error directly from the model summary. > > More generally, with some work, you could solve for the the SE for a 1 df linear hypothesis in terms of the value of the linear function of coefficients and the F or chisquare. That said, I'm not sure why you want to do this. > > I hope this helps, > John > > ----------------------------- > John Fox, Professor > McMaster University > Hamilton, Ontario > Canada L8S 4M4 > Web: socserv.mcmaster.ca/jfox > > >> -----Original Message----- >> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Steven Yen >> Sent: June 28, 2016 9:27 AM >> To: R-help <r-help at r-project.org> >> Subject: [R] t-test for regression estimate >> >> test option for linearHypothesis in library(car) include "Chisq" and "F". I prefer >> a simple t-test so that I can retrieve the standard error. >> Any options other than linearHypothesis to test the linear hypothesis (with 1 >> restriction/degree of freedom)? >> >> > summary(ols1) >> >> Coefficients: >> Estimate Std. Error t value Pr(>|t|) >> (Intercept) -0.20013 0.09199 -2.176 0.0298 * >> age 0.04054 0.01721 2.355 0.0187 * >> suburb 0.01911 0.05838 0.327 0.7435 >> smcity -0.29969 0.19175 -1.563 0.1184 >> --- >> Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 >> >> > linearHypothesis(ols1,"suburb") >> Linear hypothesis test >> >> Hypothesis: >> suburb = 0 >> >> Model 1: restricted model >> Model 2: polideo ~ age + suburb + smcity >> >> Res.Df RSS Df Sum of Sq F Pr(>F) >> 1 888 650.10 >> 2 887 650.02 1 0.078534 0.1072 0.7435 >> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.[[alternative HTML version deleted]]
Hello All, I am working on a linear regression model and trying to find the best subset of variables for my dataset. I have 21 predictors, 1 response variable, and 79 observations. I need to find the best 5 or 6 predictors for my model. I've used leaps for lm() and I'm now trying bestglm for glm(). I'm following this webpage, which gives the code below.?https://rstudio-pubs-static.s3.amazonaws.com/2897_9220b21cfc0c43a396ff9abf122bb351.html My code:library(bestglm)library(base)lbw.for.bestglm <- within(df_Chl, {y <- df_Chl$Chloro })res.bestglm <- bestglm(Xy = lbw.for.bestglm, family = gaussian, IC = "AIC", method = "exhaustive") # get coefficientsres.bestglm$BestModelsHere is a sample of my results (I removed the 5th through 21st predictors for brevity).> res.bestglm$BestModels? ? R21 ? R31 ? R32 ? R41?1 FALSE FALSE FALSE FALSE ?2 FALSE ?TRUE FALSE FALSE ?3 FALSE FALSE FALSE FALSE?4 FALSE ?TRUE FALSE FALSE?5 FALSE ?TRUE FALSE FALSE ?Criterion1 ?326.73272 ?326.95253 ?327.06594 ?327.09125 ?327.8208 Is it correct to assume I should keep variables that are TRUE from 1 through 5? What do those five rows represent?? I know the AIC criterion result should be as low as possible. Is it possible to discern a good result for any of the IC criterion results, such as AIC, LOOCV, BICg, etc..? If BIC returns lower Criterion results, does that mean I need to use the BIC subset instead of the subset from AIC? Thank You, Doug [[alternative HTML version deleted]]