0
$\begingroup$

Assuming a simple linear model $y=x\beta+u$, is there a way to test the hypothesis $\beta=c$ with $c\neq 0$, using the LinearModelFit?

$\endgroup$
2
  • $\begingroup$ I think I know what you mean, but you really should elaborate: you want to test if the slope is equal to a given value? $\endgroup$ Jun 17, 2016 at 17:16
  • $\begingroup$ @J.M. Yes, you're right. Usually, we would use a wald test for large sample. I don't see that option in Mathematica $\endgroup$ Jun 17, 2016 at 19:15

1 Answer 1

2
$\begingroup$

There are lots of ways. Here's one for performing a two-sided test of the slope equaling $c$ by getting the P-value:

data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}};
lm = LinearModelFit[data, x, x];
slopeInfo = lm["ParameterTableEntries"][[2]];
df = lm["ANOVATableDegreesOfFreedom"][[2]];

c = 2;
testStatistic = (slopeInfo[[1]] - c)/slopeInfo[[2]];
pValue = CDF[StudentTDistribution[df], -Abs[testStatistic]] +
  1 - CDF[StudentTDistribution[df], Abs[testStatistic]]
(* 0.0308905 *)

A quicker approach is to subtract $c x$ from each $y$ and then test for the resulting slope being zero.

data2 = data;
c = 2;
data2[[All, 2]] = data[[All, 2]] - c*data[[All, 1]];
lm = LinearModelFit[data2, x, x];
lm["ANOVATableEntries"][[1, 5]]
(* 0.0308905 *)

An even shorter approach uses LinearOffsetFunction.

c = 2;
lm = LinearModelFit[data, x, x, LinearOffsetFunction -> (c*# &)]
lm["ParameterTableEntries"][[2, 4]]
(* 0.0308905 *)

But one shouldn't just use a P-value to make a decision and, of course, one should only do this when a linear fit is appropriate.

$\endgroup$
2
  • $\begingroup$ One could also consider returning a confidence interval instead of a $p$-value. Anyway, for your "quicker approach", one could use an appropriate dot product instead to generate data2: lm = LinearModelFit[data.{{1, -c}, {0, 1}}, x, x]. $\endgroup$ Jun 17, 2016 at 22:53
  • $\begingroup$ @J.M. I agree about the confidence intervals. Those would be much more informative and more direct as one would not have to go through the gyrations to get a P-value for a hypothesis test. (Although the gyrations are interesting...) And, thanks, I'll use the dot product next rather than constructing a separate data set. $\endgroup$
    – JimB
    Jun 17, 2016 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.