How to do a hypothesis test of a coefficient’s significance (in R)
Task
Let’s say we have a linear model, either one variable or many. How do we conduct a test of significance for the coefficient of a single explanatory variable in the model? Similarly, how can we determine if an explanatory variable has a significant impact on the response variable?
Related tasks:
- How to compute a confidence interval for the difference between two proportions
- How to do a hypothesis test for a mean difference (matched pairs)
- How to do a hypothesis test for a population proportion
- How to do a hypothesis test for population variance
- How to do a hypothesis test for the difference between means when both population variances are known
- How to do a hypothesis test for the difference between two proportions
- How to do a hypothesis test for the mean with known standard deviation
- How to do a hypothesis test for the ratio of two population variances
- How to do a one-sided hypothesis test for two sample means
- How to do a two-sided hypothesis test for a sample mean
- How to do a two-sided hypothesis test for two sample means
Solution
We will use the fake data shown below with a single variable model. You can use a model created from your own actual data instead.
1
2
3
x <- c( 34, 9, 78, 60, 22, 45, 83, 59, 25)
y <- c(126, 347, 298, 309, 450, 187, 266, 385, 400)
model <- lm(y ~ x)
We can test whether a coefficient is zero by using that as our null hypothesis,
The answer to our hypothesis test can be obtained by looking at just the coefficients portion of the model summary:
1
summary(model)$coef
Estimate Std. Error t value Pr(>|t|)
(Intercept) 354.082248 76.732772 4.6144853 0.002441995
x -1.009013 1.472939 -0.6850334 0.515358250
The final column of output shows
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Elizabeth Czarniak (CZARNIA_ELIZ@bentley.edu)