[英]In R how to get the p-value (significance level) for selected variables rather than all variables (F-test) from a linear regression?
假設我有一個結局Y(心臟病),並且我對4個獨立變量(A,B,C,D)對Y的影響感興趣。我還想考慮年齡和性別的信息。 所以我的模型是:
model1=lm(Y~A+B+C+D+age+sex,data=MyData,na.action=na.omit)
我知道,從F檢驗中我可以得到一個p值,該值代表模型中所有變量的顯着性水平。 但是,如果我只想獲得一個p值,該怎么辦呢?它只代表了model1中A,B,C,D和4個變量的顯着性水平(我在model1中仍然有年齡和性別)。
非常感謝你。
這是mtcars
數據集的示例。 由於我沒有您的數據,因此無法准確地再現您的問題。
# 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"), ]
因此,就您的代碼而言,
summary(model1)$coefficients[c("A","B","C","D"), ]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.