Hi. Say I have a model like y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e and I want to test H0: B2/B1 = 0 or H0: B2/B1=B4/B3 (whatever H1). How can I proceed? I now about car::linearHypothesis, but I can't figure out a way to do the tests above. Any hint? Thanks. C
Søren Højsgaard
2014-Sep-06 04:48 UTC
[R] Testing general hypotheses on regression coefficients
AFAICS you are not testing a linear hypothesis (which is of the form Lb=b0 where L is a matrix and b=(a,B1,B2,B3,B3) is the parameter vector). If, for simplicity, your model is E(y) = a + bx then -a/b is the x-value for which y is zero. When you turn to estimates then u = -a/b is the ratio of two (typically correlated) normal variables and such a ratio is *not* normal. (Just think of the Cauchy distribution.) One approach is to calculate the approximate variance of u and then construct a Wald test or similar while hoping for the best. Alternatively one could perhaps try with a parametric bootstrap test. Just ideas. Good luck. S?ren -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Chris Sent: 6. september 2014 04:17 To: r-help at stat.math.ethz.ch Subject: [R] Testing general hypotheses on regression coefficients Hi. Say I have a model like y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e and I want to test H0: B2/B1 = 0 or H0: B2/B1=B4/B3 (whatever H1). How can I proceed? I now about car::linearHypothesis, but I can't figure out a way to do the tests above. Any hint? Thanks. C ______________________________________________ R-help at 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
2014-Sep-06 04:56 UTC
[R] Testing general hypotheses on regression coefficients
Well: 1) 8th grade algebra tells me B2/B1 == 0 <==> B2 =0; 2) I suspect you would need to provide more context for the other, as you may be going about this entirely incorrectly (have you consulted a local statistician?): your nonlinear hypothesis probably can be made linear under the right parametrization, but context might suggest something entirely different than the approach that motivated your query. 3) But forget all that! -- this is a list about the R language, not statistics -- which seems to be the essence of your query -- although I grant that the intersection is nonempty. But for statistics help, you should try a statistics list like stats.stackexchange.com instead. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Fri, Sep 5, 2014 at 7:17 PM, Chris <bonsxanco at yahoo.com> wrote:> Hi. > > Say I have a model like > > y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e > > and I want to test > > H0: B2/B1 = 0 > > or > > H0: B2/B1=B4/B3 > > (whatever H1). How can I proceed? > > I now about car::linearHypothesis, but I can't figure out a way to do the > tests above. > > Any hint? > > Thanks. > > C > > ______________________________________________ > R-help at 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.
Others have discussed some of the theoretical approaches (delta method), but as has also been pointed out, this is a mailing list about R, not theory, so here are some approaches to your question from the approach of those of us who like programming R more than remembering theory. I assume that one reason you may be interested in B2/B1 is that you want the confidence interval on the quantity, not just the test of whether it is 0 (that test being equivalent to B2=0 unless B1 is exactly equal to 0). So I will focus more on confidence intervals (which you can use as tests by seeing if the null value is in the interval/region or not). Approach 1, simulation: If all the assumptions hold for the linear regression, then the parameter estimates are considered to by multivariate normal. You can get the covariance matrix for this normal using the vcov function on the summary of your fitted object. Now you can use the mvrnorm function with the estimated means and covariance to generate a bunch of observations from this multivariate normal and compute B2/B1 or some combination of B2/B1 and B4/B3 for each observation. These values represent the distribution of interest and you can calculate a confidence interval by finding the quantiles of the values (0.025 and 0.975 for 95%) or finding the HPD interval (minimum width interval), the emp.hpd function in the TeachingDemos package is one way to do this. For your second hypothesis you could look at B2/B1 - B4/B3 = 0 or (B2/B1) / (B4/B3) = 1, or create a joint confidence region on the 2 ratios and see if the x=y line intersects that region. Approach 2, bootstrap: Bootstrap the whole process, fit the regression model then find the ratio of the estimates. Find the bootstrap confidence interval of the ratio(s), follow above advice. Approach 3, Bayes: Fit a Bayesian regression model and look at the posterior distribution of the ratio(s) of interest, calculate the credible interval/region (the steps will be similar to the previous approaches). Approach 4, simulate from the null: Fit your regression model under then null hypothesis of interest being true (for a more complicated null, your second, you may need to use optimization or quadratic programming to allow some values to vary, but have others dependent on those, then find the least squares solution). Now simulate data based on that model, fit the full regression to the simulated data sets and compare the parameter estimates (or ratios thereof) to the parameter estimates from the original data. You could try any of these approaches for hypotheses where traditional linear hypotheses work and compare the results from the traditional approach to the above approaches to see how they compare (and how many iterations/samples you will need). On Fri, Sep 5, 2014 at 8:17 PM, Chris <bonsxanco at yahoo.com> wrote:> Hi. > > Say I have a model like > > y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e > > and I want to test > > H0: B2/B1 = 0 > > or > > H0: B2/B1=B4/B3 > > (whatever H1). How can I proceed? > > I now about car::linearHypothesis, but I can't figure out a way to do the > tests above. > > Any hint? > > Thanks. > > C > > ______________________________________________ > R-help at 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com