Thanks John. Yes, by using verbose=T, I get the value of the hypothesis. But tell me again, how would I get the variance (standard error)? On 6/29/2016 11:56 AM, Fox, John wrote:> Dear Steven, > > OK -- that makes sense, and there was also a previous request for linearHypothesis() to return the value of the hypothesis and its covariance matrix. In your case, where there's only 1 numerator df, that would be the value and estimated sampling variance of the hypothesis. > > I've now implemented that, using (at least provisionally) attributes in the development version of the car package on R-Forge, which you should be able to install via install.packages("car", repos="http://R-Forge.R-project.org"). Then see ?linearHypothesis for more information. > > Best, > John > >> -----Original Message----- >> From: Steven Yen [mailto:syen04 at gmail.com] >> Sent: June 28, 2016 3:44 PM >> To: Fox, John <jfox at mcmaster.ca> >> Cc: R-help <r-help at r-project.org> >> Subject: Re: [R] t-test for regression estimate >> >> 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> <mailto: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 <mailto: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]]
Also, Is there a way to get the second command (hypothesis defined with externally scalars) below to work? Thanks. linearHypothesis(U,"0.5*eq1_DQ+0.3*eq2_DQ",verbose=T) w1<-0.5; w2<-0.3 linearHypothesis(U,"w1*eq1_DQ+w2*eq2_DQ",verbose=T) # does not work On 6/29/2016 12:38 PM, Steven Yen wrote:> Thanks John. Yes, by using verbose=T, I get the value of the > hypothesis. But tell me again, how would I get the variance (standard > error)? > > On 6/29/2016 11:56 AM, Fox, John wrote: >> Dear Steven, >> >> OK -- that makes sense, and there was also a previous request for linearHypothesis() to return the value of the hypothesis and its covariance matrix. In your case, where there's only 1 numerator df, that would be the value and estimated sampling variance of the hypothesis. >> >> I've now implemented that, using (at least provisionally) attributes in the development version of the car package on R-Forge, which you should be able to install via install.packages("car", repos="http://R-Forge.R-project.org"). Then see ?linearHypothesis for more information. >> >> Best, >> John >> >>> -----Original Message----- >>> From: Steven Yen [mailto:syen04 at gmail.com] >>> Sent: June 28, 2016 3:44 PM >>> To: Fox, John<jfox at mcmaster.ca> >>> Cc: R-help<r-help at r-project.org> >>> Subject: Re: [R] t-test for regression estimate >>> >>> 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> <mailto: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 <mailto: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 guidehttp://www.R- >>> project.org/posting- >>> guide.html >>> and provide commented, minimal, self-contained, reproducible >>> code. >>> >[[alternative HTML version deleted]]
Dear Steven,> -----Original Message----- > From: Steven Yen [mailto:syen04 at gmail.com] > Sent: June 29, 2016 9:39 AM > To: Fox, John <jfox at mcmaster.ca> > Cc: R-help <r-help at r-project.org>; Sandy Weisberg (sandy at umn.edu) > <sandy at umn.edu> > Subject: Re: [R] t-test for regression estimate > > Thanks John. Yes, by using verbose=T, I get the value of the hypothesis. But tell > me again, how would I get the variance (standard error)?Using verbose=TRUE *prints* the value of the hypothesis but doesn't save it in the returned object, making it inconvenient to compute on it. As well, when verbose is TRUE we should probably also print the covariance matrix for the hypothesis, which we don't do at present, but which I'll add when I have a chance. From ?linearHypothesis in the development version of car: "The value of the linear hypothesis and its covariance matrix are returned respectively as "value" and "vcov" attributes of the object (but not printed)." Thus, for example, ---------------- snip ------------> library(car) > mod <- lm(prestige ~ income + education, data=Duncan) > lh <- linearHypothesis(mod, "income = education"))> attr(lh, "value")[,1] income = education 0.05289891> attr(lh, "vcov")income = education income = education 0.04101096 ---------------- snip ------------ The reason that l used attributes is that linearHypothesis() returns an "anova" object, which is printed by print.anova(). Adding components directly to that object would disturb printing it. I could introduce a new class of objects but, though that would be more intuitive, and though I may end up doing that, it is probably unwarranted given the rarity of wanting to access the value and covariance matrix of the hypothesis. Best, John> > > On 6/29/2016 11:56 AM, Fox, John wrote: > > > Dear Steven, > > OK -- that makes sense, and there was also a previous request for > linearHypothesis() to return the value of the hypothesis and its covariance > matrix. In your case, where there's only 1 numerator df, that would be the > value and estimated sampling variance of the hypothesis. > > I've now implemented that, using (at least provisionally) attributes in > the development version of the car package on R-Forge, which you should be > able to install via install.packages("car", repos="http://R-Forge.R-project.org" > <http://R-Forge.R-project.org> ). Then see ?linearHypothesis for more > information. > > Best, > John > > > -----Original Message----- > From: Steven Yen [mailto:syen04 at gmail.com] > Sent: June 28, 2016 3:44 PM > To: Fox, John <jfox at mcmaster.ca> > <mailto:jfox at mcmaster.ca> > Cc: R-help <r-help at r-project.org> <mailto:r-help at r- > project.org> > Subject: Re: [R] t-test for regression estimate > > 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> <mailto:r- > help at r-project.org> <mailto:r-help at r- > project.org> <mailto: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 <mailto:R-help at r- > project.org> <mailto:R-help at r-project.org> <mailto: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. > > > >
Dear Steven,> -----Original Message----- > From: Steven Yen [mailto:syen04 at gmail.com] > Sent: June 29, 2016 9:48 AM > To: Fox, John <jfox at mcmaster.ca> > Cc: R-help <r-help at r-project.org>; Sandy Weisberg (sandy at umn.edu) > <sandy at umn.edu> > Subject: Re: [R] t-test for regression estimate > > Also, > Is there a way to get the second command (hypothesis defined with externally > scalars) below to work? Thanks. > > linearHypothesis(U,"0.5*eq1_DQ+0.3*eq2_DQ",verbose=T) > w1<-0.5; w2<-0.3 > linearHypothesis(U,"w1*eq1_DQ+w2*eq2_DQ",verbose=T) # does not workYou can specify the hypothesis matrix (a vector in the 1-df case). E.g., ----------------- snip ---------------------> library(car) > mod <- lm(prestige ~ income + education, data=Duncan) > one <- 1 > minus.one <- -1 > linearHypothesis(mod, c(0, one, minus.one)) # 0 * the interceptLinear hypothesis test Hypothesis: income - education = 0 Model 1: restricted model Model 2: prestige ~ income + education Res.Df RSS Df Sum of Sq F Pr(>F) 1 43 7518.9 2 42 7506.7 1 12.195 0.0682 0.7952 ----------------- snip --------------------- John> > > On 6/29/2016 12:38 PM, Steven Yen wrote: > > > Thanks John. Yes, by using verbose=T, I get the value of the hypothesis. > But tell me again, how would I get the variance (standard error)? > > > On 6/29/2016 11:56 AM, Fox, John wrote: > > > Dear Steven, > > OK -- that makes sense, and there was also a previous request > for linearHypothesis() to return the value of the hypothesis and its covariance > matrix. In your case, where there's only 1 numerator df, that would be the > value and estimated sampling variance of the hypothesis. > > I've now implemented that, using (at least provisionally) > attributes in the development version of the car package on R-Forge, which you > should be able to install via install.packages("car", repos="http://R-Forge.R- > project.org" <http://R-Forge.R-project.org> ). Then see ?linearHypothesis for > more information. > > Best, > John > > > -----Original Message----- > From: Steven Yen [mailto:syen04 at gmail.com] > Sent: June 28, 2016 3:44 PM > To: Fox, John <jfox at mcmaster.ca> > <mailto:jfox at mcmaster.ca> > Cc: R-help <r-help at r-project.org> <mailto:r-help at r- > project.org> > Subject: Re: [R] t-test for regression estimate > > 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> > <mailto:r-help at r-project.org> <mailto:r-help at r- > project.org> <mailto: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 <mailto:R- > help at r-project.org> <mailto:R-help at r-project.org> <mailto: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. > > >