Chestnut T
Chestnut T

Reputation: 39

In R how to get the p-value (significance level) for selected variables rather than all variables (F-test) from a linear regression?

Suppose I have one outcome Y (heart disease) and I'm interested in the impact from 4 independent variables(A,B,C,D) on Y. Also I want to take into account the information of age and sex. So my model is:

model1=lm(Y~A+B+C+D+age+sex,data=MyData,na.action=na.omit)

I know, from F-test I can get a p-value represent the significance level of all variables in the model. But what can I do if I just want to get one p-value just represent the significance level of A,B,C,D, 4 variables from model1(I still have age and sex in model1).

Thank you very much.

Upvotes: 0

Views: 1580

Answers (1)

Øystein S
Øystein S

Reputation: 644

Here is an example, with the mtcars dataset. Since I do not have your data, I cannot reproduce exactly your problem.

# Model with many variables
mod <- lm(mpg ~ cyl + disp + hp + drat, data = mtcars)

# Show p-values for variables cyl and disp only, but using the full model
summary(mod)$coefficients[c("cyl", "disp"), ]

So in terms of your code, try

summary(model1)$coefficients[c("A","B","C","D"), ]

Upvotes: 1

Related Questions