Re: [R] Hausman test
> On Feb 11, 2018, at 8:29 AM, PAOLO PILIwrote: > > you are right about the 3rd line but it doesn't help me for my problem. I > remove the 3rd line but there is still the same problem: > > Error in solve.default (dvcov): > the system is numerically unique: reciprocity condition value = > 1.63418e-19 That suggests inclusion of too many categorical (factor) variables relative to the sample size in the predictor variables. Use tabular methods to investigate. Unable to be more specific in the absence of a proper description of the data situation. -- David. > > Paolo > > 2018-02-11 16:54 GMT+01:00 Bert Gunter : > >> Note the typo in your 3rd line: data < >> >> Don't know if this means anything... >> >> Bert >> >> >> >> On Feb 11, 2018 7:33 AM, "PAOLO PILI" wrote: >> >>> Hello, >>> >>> I have a problem with Hausman test. I am performing my analysis with these >>> commands: >>> library(plm) data<-read.csv2("paolo.csv",header=TRUE) data< >>> pdata.frame(data,index=c("FIRM","YEAR"),drop.index=TRUE,row.names=TRUE) >>> RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+NGROWTH+TU >>> RN+GPROF+GPROF2 >>> grun.fe<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROW >>> TH+NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") grun.re >>> <-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+NGRO >>> WTH+TURN+GPROF+GPROF2,data=data,model="random") >>> gw<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+ >>> NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") >>> gr<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+ >>> NGROWTH+TURN+GPROF+GPROF2,data=data,model="random") phtest(gw,gr) >>> >>> I got this answer: >>> >>> Error in solve.default(dvcov) : >>> >>> how can I solve this problem? >>> >>> Thank you >>> >>>[[alternative HTML version deleted]] >>> >>> __ >>> R-help@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/posti >>> ng-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> > > [[alternative HTML version deleted]] > > __ > R-help@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. David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law __ R-help@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.
Re: [R] Hausman test
you are right about the 3rd line but it doesn't help me for my problem. I remove the 3rd line but there is still the same problem: Error in solve.default (dvcov): the system is numerically unique: reciprocity condition value = 1.63418e-19 Paolo 2018-02-11 16:54 GMT+01:00 Bert Gunter: > Note the typo in your 3rd line: data < > > Don't know if this means anything... > > Bert > > > > On Feb 11, 2018 7:33 AM, "PAOLO PILI" wrote: > >> Hello, >> >> I have a problem with Hausman test. I am performing my analysis with these >> commands: >> >> > library(plm) >> > data<-read.csv2("paolo.csv",header=TRUE) >> > data< >> pdata.frame(data,index=c("FIRM","YEAR"),drop.index=TRUE,row.names=TRUE) >> > >> RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+NGROWTH+TU >> RN+GPROF+GPROF2 >> > >> grun.fe<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROW >> TH+NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") >> > grun.re >> <-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+NGRO >> WTH+TURN+GPROF+GPROF2,data=data,model="random") >> > >> gw<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+ >> NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") >> > >> gr<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+ >> NGROWTH+TURN+GPROF+GPROF2,data=data,model="random") >> > phtest(gw,gr) >> >> I got this answer: >> >> Error in solve.default(dvcov) : >> >> how can I solve this problem? >> >> Thank you >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@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/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Hausman test
Note the typo in your 3rd line: data < Don't know if this means anything... Bert On Feb 11, 2018 7:33 AM, "PAOLO PILI"wrote: > Hello, > > I have a problem with Hausman test. I am performing my analysis with these > commands: > > > library(plm) > > data<-read.csv2("paolo.csv",header=TRUE) > > data< > pdata.frame(data,index=c("FIRM","YEAR"),drop.index=TRUE,row.names=TRUE) > > > RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+NGROWTH+ > TURN+GPROF+GPROF2 > > > grun.fe<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+ > PGROWTH+NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") > > grun.re > <-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+PGROWTH+ > NGROWTH+TURN+GPROF+GPROF2,data=data,model="random") > > > gw<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+ > PGROWTH+NGROWTH+TURN+GPROF+GPROF2,data=data,model="within") > > > gr<-plm(RECEIV~LSIZE+LAGE+LAGE2+CFLOW+STLEV+FCOST+ > PGROWTH+NGROWTH+TURN+GPROF+GPROF2,data=data,model="random") > > phtest(gw,gr) > > I got this answer: > > Error in solve.default(dvcov) : > > how can I solve this problem? > > Thank you > > [[alternative HTML version deleted]] > > __ > R-help@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]] __ R-help@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.
Re: [R] Hausman Test
On Mon, 12 Sep 2016, Ding, Jie Ding (NIH/NIA/ERP) [F] wrote: Dear Achim, Sorry to have disturbed you. I have encountered a problem when computing Hausman test statistics (i.e. p values) in R to compare OLS and 2SLS models. The problem is a discrepancy between the two p-value outputs from the "manual approach (by hand)" and the " diagnostics argument" in the "AER" library, respectively. With respect to manual approach, I used the following codes: cf_diff<-coef(ivreg)-coef(olsreg) vc_diff<-vcov(ivreg)-vcov(olsreg) x2_diff<-as.vector(t(cf_diff)%*% solve(vc_diff)%*%cf_diff) pchisq(x2_diff,df=2,lower.tail=FALSE) For diagnostic approach, I applied the following: summary(ivreg, vcov = sandwich, df = Inf, diagnostics = TRUE) However, p-value from the manual approach is always much larger than the diagnostic approach, e.g. 0.329 vs. 0.138 I would expect the values should be the same. Your advice would be highly appreciated. The Wu-Hausman test in ivreg() follows the auugmented regression approach that is also used by Stata. This regresses the endogenous variable on the instruments and includes the fitted values in an OLS regression. The test is then a simple Wald test, see: http://www.stata.com/support/faqs/statistics/durbin-wu-hausman-test/ With very best wishes, Jennifer [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] Hausman Test
Dear Achim, Sorry to have disturbed you. I have encountered a problem when computing Hausman test statistics (i.e. p values) in R to compare OLS and 2SLS models. The problem is a discrepancy between the two p-value outputs from the "manual approach (by hand)" and the " diagnostics argument" in the "AER" library, respectively. With respect to manual approach, I used the following codes: cf_diff<-coef(ivreg)-coef(olsreg) vc_diff<-vcov(ivreg)-vcov(olsreg) x2_diff<-as.vector(t(cf_diff)%*% solve(vc_diff)%*%cf_diff) pchisq(x2_diff,df=2,lower.tail=FALSE) For diagnostic approach, I applied the following: summary(ivreg, vcov = sandwich, df = Inf, diagnostics = TRUE) However, p-value from the manual approach is always much larger than the diagnostic approach, e.g. 0.329 vs. 0.138 I would expect the values should be the same. Your advice would be highly appreciated. With very best wishes, Jennifer [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Hausman Test trouble - plm
Might have just solved my own problem team! I assumed that the issue here was the replicated samples, and so added a column and gave a number to each replicate. R seemed to like this and was happy to run the test! A significant result tells me that the fixed effects model is the most preferable model to explain the variation seen in my data. Unless I am doing/assuming something wrong here that you can see then I might well have solved my own problem. Let me know if you have any thoughts :) Cheers -- View this message in context: http://r.789695.n4.nabble.com/Hausman-Test-trouble-plm-tp4709990p4709992.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Hausman test in R
Hello. Well said Joshua. May I add that in an OLS context (which i take as also meaning: no panel structure) what you probably want to do is the so-called Durbin-Wu-Hausman test for endogeneity, as explained e.g. here: http://kurt.schmidheiny.name/teaching/iv2up.pdf see Section 11 for the idea, and 13 for the R implementation. Best wishes, Giovanni -- original message Date: Sun, 28 Oct 2012 16:03:43 -0700 From: Joshua Wiley jwiley.ps...@gmail.com To: fxen3k f.seha...@gmail.com Cc: r-help@r-project.org Subject: Re: [R] Hausman test in R Message-ID: canz9z_+2k3qwazrazqz09nsfaj_431a2ylrpgswvnbo6pon...@mail.gmail.com Content-Type: text/plain Hi, I can think of no reason a Hausman test could not be used for OLS---it is a comparison of vectors of coefficients from different models usually assumed to produce similar estimates under certain conditions. Dissimilarity is taken as indicative of a lack of some or all the conditions required for the two models to yield similar parameters. I suggest you look at the plm and systemfit packages. They have many functions for OLS, 2SLS, tests of endogeneity, etc. The plm (and maybe systemfit?) package also has a vignette which is a good thing to read. It has a lot of useful information on the code and examples of comparing different types of models, that you may find instructive. Hope this helps, Josh On Sun, Oct 28, 2012 at 1:33 PM, fxen3k f.seha...@gmail.com wrote: Hi there, I am really new to statistics in R and statistics itself as well. My situation: I ran a lot of OLS regressions with different independent variables. (using the lm() function). After having done that, I know there is endogeneity due to omitted variables. (or perhaps due to any other reasons). And here comes the Hausman test. I know this test is used to identify endogeneity. But what I am not sure about is: Can I use the Hausman test in a simple OLS regression or is it only possible in a 2SLS regression model? And if it is possible to use it, how can I do it? Info about the data: data = lots of data :) x1 - data$x1 x2 - data$x2 x3 - data$x3 x4 - data$x4 y1 - data$y1 reg1 - summary(lm(y1 ~ x1 + x2 + x3 + x4)) Thanks in advance for any support! -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ --- end original message - Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}} __ 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] Hausman test in R
Given my acknowledged statistical ignorance, I tried to find a *solution *in this forum... And this is not primarily a statistical issue, it is an issue about the Hausman test in the R environment. I cannot imagine, no one in this forum has ever done a Hausman test on OLS regressions. I read in the systemfit package and found only this example referring to 2SLS and 3SLS regressions: data( Kmenta ) eqDemand - consump ~ price + income eqSupply - consump ~ price + farmPrice + trend inst - ~ income + farmPrice + trend system - list( demand = eqDemand, supply = eqSupply ) ## perform the estimations fit2sls - systemfit( system, 2SLS, inst = inst, data = Kmenta ) fit3sls - systemfit( system, 3SLS, inst = inst, data = Kmenta ) ## perform the Hausman test h - hausman.systemfit( fit2sls, fit3sls ) print( h ) -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716p4647774.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman test in R
On 29 October 2012 16:56, fxen3k f.seha...@gmail.com wrote: snip If we are talking about the same test a Hausman test can not be applied to OLS regressions. As you have already been told you must have two estimates of the same set of coefficients to do a Hausman test. Suppose that you do OLS and an IV estimates of a particular regression you will get twu estimates of the coefficients in the model. If the disturbances are not correlated with the explanatory variables (no endogeneity) the two sets of coefficients will no be similar. If there is endogeneity the coefficients will be different. The Hausman test is a test of the null that the coefficients are not different. If the null is accepted you will probably accept the OLS regression. If the null is rejected you may consider the IV estimate. A Hausman test is applicable in many other situations (fixed v random effects etc.) You may have problems with the estimate of the covariance matrix used in the test as on occasion as, due to numerical problems, the estimates of that matrix are not always positive definite. Most intermediate level econometrics textbooks will have a good account of the Hausman test. Green(2012), Econometric Analysis 7th edition, Prentice Hall. contains a comprehensive discussion of these matters which you might read. It is not easy but if you master the basic concepts there, your questions about their implementation in R are likely to be answered on this forum. Best Regards John I cannot imagine, no one in this forum has ever done a Hausman test on OLS regressions. I read in the systemfit package and found only this example referring to 2SLS and 3SLS regressions: data( Kmenta ) eqDemand - consump ~ price + income eqSupply - consump ~ price + farmPrice + trend inst - ~ income + farmPrice + trend system - list( demand = eqDemand, supply = eqSupply ) ## perform the estimations fit2sls - systemfit( system, 2SLS, inst = inst, data = Kmenta ) fit3sls - systemfit( system, 3SLS, inst = inst, data = Kmenta ) ## perform the Hausman test h - hausman.systemfit( fit2sls, fit3sls ) print( h ) -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716p4647774.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- John C Frain Economics Department Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:fra...@tcd.ie mailto:fra...@gmail.com __ 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] Hausman test in R
Thanks for your answer, John! Having read in Wooldridge, Verbeek and Hausman himself, I tried to figure out how this whole Hausman test works. I tried to figure out, if endogeneity exists in my particular case. So I did this Y ~ X + Z + Rest + error term [# this is the the original regression with Z = instrumental variable for X, X = potentially endogenous variable and Rest = more independent variables] Regression 1: X ~ Z + Rest + error term Regression 2: Y ~ X + Rest + residuals(Reg1) + error [# I took the residuals from Regression 1 by Reg1_resid - cbind(Red1$resid) Finally, if the coefficient for the residuals is statistically significant, there is endogeneity. Is this approach correct? p.s: My p-value is 0.1138... Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716p4647800.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman test in R
1. These are primarily statistics issues, not R issues. You should post on a statistical help list like stats.stackexchange.com, not here. 2. However, given your acknowledged statistical ignorance, you may be asking for trouble. I suggest you seek help from a local statistical expert to get you started. Then, depending on your statistical background, you may understand enough to drive safely on your own. Also try at the R command prompt: install.packages(fortunes) library(fortunes) fortune(brain surgery) Cheers, Bert On Sun, Oct 28, 2012 at 1:33 PM, fxen3k f.seha...@gmail.com wrote: Hi there, I am really new to statistics in R and statistics itself as well. My situation: I ran a lot of OLS regressions with different independent variables. (using the lm() function). After having done that, I know there is endogeneity due to omitted variables. (or perhaps due to any other reasons). And here comes the Hausman test. I know this test is used to identify endogeneity. But what I am not sure about is: Can I use the Hausman test in a simple OLS regression or is it only possible in a 2SLS regression model? And if it is possible to use it, how can I do it? Info about the data: data = lots of data :) x1 - data$x1 x2 - data$x2 x3 - data$x3 x4 - data$x4 y1 - data$y1 reg1 - summary(lm(y1 ~ x1 + x2 + x3 + x4)) Thanks in advance for any support! -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Hausman test in R
Hi, I can think of no reason a Hausman test could not be used for OLS---it is a comparison of vectors of coefficients from different models usually assumed to produce similar estimates under certain conditions. Dissimilarity is taken as indicative of a lack of some or all the conditions required for the two models to yield similar parameters. I suggest you look at the plm and systemfit packages. They have many functions for OLS, 2SLS, tests of endogeneity, etc. The plm (and maybe systemfit?) package also has a vignette which is a good thing to read. It has a lot of useful information on the code and examples of comparing different types of models, that you may find instructive. Hope this helps, Josh On Sun, Oct 28, 2012 at 1:33 PM, fxen3k f.seha...@gmail.com wrote: Hi there, I am really new to statistics in R and statistics itself as well. My situation: I ran a lot of OLS regressions with different independent variables. (using the lm() function). After having done that, I know there is endogeneity due to omitted variables. (or perhaps due to any other reasons). And here comes the Hausman test. I know this test is used to identify endogeneity. But what I am not sure about is: Can I use the Hausman test in a simple OLS regression or is it only possible in a 2SLS regression model? And if it is possible to use it, how can I do it? Info about the data: data = lots of data :) x1 - data$x1 x2 - data$x2 x3 - data$x3 x4 - data$x4 y1 - data$y1 reg1 - summary(lm(y1 ~ x1 + x2 + x3 + x4)) Thanks in advance for any support! -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-in-R-tp4647716.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ [[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] Hausman Test
On Sun, 16 Jan 2011, Holger Steinmetz wrote: Hi, can anybody tell me how the Hausman test for endogenty works? I have a simulated model with three correlated predictors (X1-X3). I also have an instrument W for X1 Now I want to test for endogeneity of X1 (i.e., when I omit X2 and X3 from the equation). My current approach: library(systemfit) fit2sls - systemfit(Y~X1,data=data,method=2SLS,inst=~W) fitOLS - systemfit(Y~X1,data=data,method=OLS) print(hausman.systemfit(fitOLS, fit2sls)) This seems to work fine. However, when I include X2 as a furter predictor, the 2sls-estimation doesn't work. When you don't need any instruments for X2, then you should employ Y ~ X1 + X2, inst = ~ W + X2 Then, regressor X2 is unaltered in the second stage of the regression (after projection onto the instruments). hth, Z Thanks in advance Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-Test-tp3220016p3220016.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Hausman Test
Dear Achim, thank you very much. One follow up question. The Hausman-test always gives me a p-value of 1 - no matter how small the statistic is. I now generated orthogonal regressors (X1-X3) and the test gives me Hausman specification test for consistency of the 3SLS estimation data: data Hausman = -0.0138, df = 2, p-value = 1 What is confusing to me is the 3SLS. I am just beginning to learn about instrumental variables (I am a psychologist ;) Perhaps that's a problem? As a background, here's the complete simulation: W = rnorm(1000) X2 = rnorm(1000) X3 = rnorm(1000) X1 = .5*W + rnorm(1000) Y = .4*X1 + .5*X2 + .6*X3 + rnorm(1000) data = as.data.frame(cbind(X1,X2,X3,Y,W)) fit2sls - systemfit(Y~X1,data=data,method=2SLS,inst=~W) fitOLS - systemfit(Y~X1,data=data,method=OLS) print(hausman.systemfit(fitOLS, fit2sls)) Best, Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-Test-tp3220016p3220065.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman Test
Hi Holger! On 16 January 2011 15:53, Holger Steinmetz holger.steinm...@web.de wrote: One follow up question. The Hausman-test always gives me a p-value of 1 - no matter how small the statistic is. I now generated orthogonal regressors (X1-X3) and the test gives me Hausman specification test for consistency of the 3SLS estimation data: data Hausman = -0.0138, df = 2, p-value = 1 What is confusing to me is the 3SLS. I am just beginning to learn about instrumental variables (I am a psychologist ;) Perhaps that's a problem? As a background, here's the complete simulation: W = rnorm(1000) X2 = rnorm(1000) X3 = rnorm(1000) X1 = .5*W + rnorm(1000) Y = .4*X1 + .5*X2 + .6*X3 + rnorm(1000) data = as.data.frame(cbind(X1,X2,X3,Y,W)) fit2sls - systemfit(Y~X1,data=data,method=2SLS,inst=~W) fitOLS - systemfit(Y~X1,data=data,method=OLS) print(hausman.systemfit(fitOLS, fit2sls)) Please do read the documentation of hausman.systemfit(). I regret that comparing 2SLS with OLS results has not been implemented yet: == part of documentation of hausman.systemfit() = Usage: hausman.systemfit( results2sls, results3sls ) Arguments: results2sls : result of a _2SLS_ (limited information) estimation returned by ‘systemfit’. results3sls : result of a _3SLS_ (full information) estimation returned by ‘systemfit’. Details: The null hypotheses of the test is that all exogenous variables are uncorrelated with all disturbance terms. Under this hypothesis both the 2SLS and the 3SLS estimator are consistent but only the 3SLS estimator is (asymptotically) efficient. Under the alternative hypothesis the 2SLS estimator is consistent but the 3SLS estimator is inconsistent. The Hausman test statistic is m = ( b_2 - b_3 )' ( V_2 - V_3 ) ( b_2 - b_3 ) where $b_2$ and $V_2$ are the estimated coefficients and their variance covariance matrix of a _2SLS_ estimation and $b_3$ and $V_3$ are the estimated coefficients and their variance covariance matrix of a _3SLS_ estimation. = Please don't hesitate to write a new version of hausman.systemfit() that can also compare 2SLS with OLS results. Best regards from Copenhagen, Arne -- Arne Henningsen http://www.arne-henningsen.name __ 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] Hausman Test
On Sun, 16 Jan 2011, Holger Steinmetz wrote: Dear Achim, thank you very much. One follow up question. The Hausman-test always gives me a p-value of 1 - no matter how small the statistic is. I now generated orthogonal regressors (X1-X3) and the test gives me Hausman specification test for consistency of the 3SLS estimation data: data Hausman = -0.0138, df = 2, p-value = 1 What is confusing to me is the 3SLS. Hausman tests can be used for comparisons of various models. The implementation in systemfit is intended for comparison of 2SLS and 3SLS but can also be (ab)used for comparison of 2SLS and OLS. You just have to enter the models in the reverse order, i.e., hausman.systemfit(fit2sls, fitOLS). A worked example that computes the test statistic by hand is also included in help(Baltagi2002, package = AER) in the section about the US consumption data, Chapter 11. An adaptation is also shown below: ## data library(AER) data(USConsump1993, package = AER) usc - as.data.frame(USConsump1993) usc$investment - usc$income - usc$expenditure ## 2SLS via ivreg(), Hausman by hand fm_ols - lm(expenditure ~ income, data = usc) fm_iv - ivreg(expenditure ~ income | investment, data = usc) cf_diff - coef(fm_iv) - coef(fm_ols) vc_diff - vcov(fm_iv) - vcov(fm_ols) x2_diff - as.vector(t(cf_diff) %*% solve(vc_diff) %*% cf_diff) pchisq(x2_diff, df = 2, lower.tail = FALSE) ## 2SLS via systemfit(), Hausman via hausman.systemfit() library(systemfit) sm_ols - systemfit(expenditure ~ income, data = usc, method = OLS) sm_iv - systemfit(expenditure ~ income, data = usc, method = 2SLS, inst = ~ investment) hausman.systemfit(sm_iv, sm_ols) hth, Z I am just beginning to learn about instrumental variables (I am a psychologist ;) Perhaps that's a problem? As a background, here's the complete simulation: W = rnorm(1000) X2 = rnorm(1000) X3 = rnorm(1000) X1 = .5*W + rnorm(1000) Y = .4*X1 + .5*X2 + .6*X3 + rnorm(1000) data = as.data.frame(cbind(X1,X2,X3,Y,W)) fit2sls - systemfit(Y~X1,data=data,method=2SLS,inst=~W) fitOLS - systemfit(Y~X1,data=data,method=OLS) print(hausman.systemfit(fitOLS, fit2sls)) Best, Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-Test-tp3220016p3220065.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Hausman Test
On Sun, 16 Jan 2011, Arne Henningsen wrote: Hi Holger! On 16 January 2011 15:53, Holger Steinmetz holger.steinm...@web.de wrote: One follow up question. The Hausman-test always gives me a p-value of 1 - no matter how small the statistic is. I now generated orthogonal regressors (X1-X3) and the test gives me Hausman specification test for consistency of the 3SLS estimation data: data Hausman = -0.0138, df = 2, p-value = 1 What is confusing to me is the 3SLS. I am just beginning to learn about instrumental variables (I am a psychologist ;) Perhaps that's a problem? As a background, here's the complete simulation: W = rnorm(1000) X2 = rnorm(1000) X3 = rnorm(1000) X1 = .5*W + rnorm(1000) Y = .4*X1 + .5*X2 + .6*X3 + rnorm(1000) data = as.data.frame(cbind(X1,X2,X3,Y,W)) fit2sls - systemfit(Y~X1,data=data,method=2SLS,inst=~W) fitOLS - systemfit(Y~X1,data=data,method=OLS) print(hausman.systemfit(fitOLS, fit2sls)) Please do read the documentation of hausman.systemfit(). I regret that comparing 2SLS with OLS results has not been implemented yet: == part of documentation of hausman.systemfit() = Usage: hausman.systemfit( results2sls, results3sls ) Arguments: results2sls : result of a _2SLS_ (limited information) estimation returned by ?systemfit?. results3sls : result of a _3SLS_ (full information) estimation returned by ?systemfit?. Details: The null hypotheses of the test is that all exogenous variables are uncorrelated with all disturbance terms. Under this hypothesis both the 2SLS and the 3SLS estimator are consistent but only the 3SLS estimator is (asymptotically) efficient. Under the alternative hypothesis the 2SLS estimator is consistent but the 3SLS estimator is inconsistent. The Hausman test statistic is m = ( b_2 - b_3 )' ( V_2 - V_3 ) ( b_2 - b_3 ) where $b_2$ and $V_2$ are the estimated coefficients and their variance covariance matrix of a _2SLS_ estimation and $b_3$ and $V_3$ are the estimated coefficients and their variance covariance matrix of a _3SLS_ estimation. = Please don't hesitate to write a new version of hausman.systemfit() that can also compare 2SLS with OLS results. Arne: Unless I'm missing something, hausman.systemfit() essentially does the right thing and computes the right statistic and p-value (see my other mail to Holger). Maybe some preliminary check on the input objects could be used for determining the right order of models. Best, Z Best regards from Copenhagen, Arne -- Arne Henningsen http://www.arne-henningsen.name __ 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.
Re: [R] Hausman Test
Hi Achim! On 16 January 2011 16:37, Achim Zeileis achim.zeil...@uibk.ac.at wrote: Arne: Unless I'm missing something, hausman.systemfit() essentially does the right thing and computes the right statistic and p-value (see my other mail to Holger). Maybe some preliminary check on the input objects could be used for determining the right order of models. Thanks for the response and the suggestions. Adding a check for the input objects and extending the documentation is a good idea! I will change the systemfit package accordingly in the future. /Arne -- Arne Henningsen http://www.arne-henningsen.name __ 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] Hausman Test
Thank you both very much ! This helped me a lot. Best, Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-Test-tp3220016p3220123.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman test for endogeneity
... and, in fact, simply googling on R Package Hausmann finds two Hausmann test functions in 2 different packages within the first half dozen hits. -- Bert On Sat, Oct 9, 2010 at 11:06 AM, Liviu Andronic landronim...@gmail.com wrote: Hello On Sat, Oct 9, 2010 at 2:37 PM, Holger Steinmetz holger.steinm...@web.de wrote: can anybody point me in the right direction on how to conduct a hausman test for endogeneity in simultanous equation models? Try install.packages('sos') require(sos) findFn('hausman') Here I get these results: findFn('hausman') found 22 matches; retrieving 2 pages 2 Liviu __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics __ 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] Hausman test for endogeneity
Dear Liviu, thank you very much. After inspecting the options, I *guess* that systemfit is what I need. However, I absolutely don't understand how it works. I searched long for a detailed documentation (beyond the rather cryptic standard documentation) but found none. Has anybody references/advises how to conduct the test? Best, Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-for-endogeneity-tp2969522p2970261.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman test for endogeneity
Hi Holger On 10 October 2010 15:36, Holger Steinmetz holger.steinm...@web.de wrote: After inspecting the options, I *guess* that systemfit is what I need. However, I absolutely don't understand how it works. I searched long for a detailed documentation (beyond the rather cryptic standard documentation) but found none. Has anybody references/advises how to conduct the test? A paper describing the systemfit package has been published in the journal of statistical software: http://www.jstatsoft.org/v23/i04/paper It describes the Hausman test for testing the consistency of the 3SLS estimates against the 2SLS estimates (see sections 2.8 and 4.6). I guess (but I am not sure -- maybe others can comment on this) that you test for the endogeneity of regressors, e.g., by fitSur - systemfit( myFormula, data = myData, method = SUR ) fit3sls - systemfit( myFormula, data = myData, method = 3SLS, inst = myInst ) hausman.systemfit( fit3sls, fitSur ) If some regressors are endogenous, the SUR estimates are inconsistent but the 3SLS estimates are consistent given that the instrumental variables are exogenous. However, if all regressors are exogenous, both estimates should be consistent but the SUR estimates should be more efficient. Best wishes, Arne -- Arne Henningsen http://www.arne-henningsen.name __ 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] Hausman test for endogeneity
Dear Arne, this looks promising! Thank you very much. Best, Holger -- View this message in context: http://r.789695.n4.nabble.com/Hausman-test-for-endogeneity-tp2969522p2970564.html Sent from the R help mailing list archive at Nabble.com. __ 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] Hausman test for endogeneity
On Saturday 09 October 2010 14:37:35 Holger Steinmetz wrote: Dear folks, can anybody point me in the right direction on how to conduct a hausman test for endogeneity in simultanous equation models? Best, Holger hausman.systemfit [1] should be what you are looking for. Cheers Giuseppe [1] http://cran.r-project.org/web/packages/systemfit/systemfit.pdf __ 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] Hausman test for endogeneity
Hello On Sat, Oct 9, 2010 at 2:37 PM, Holger Steinmetz holger.steinm...@web.de wrote: can anybody point me in the right direction on how to conduct a hausman test for endogeneity in simultanous equation models? Try install.packages('sos') require(sos) findFn('hausman') Here I get these results: findFn('hausman') found 22 matches; retrieving 2 pages 2 Liviu __ 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.