R တွင် lm() function မှ p တန်ဖိုးများကို မည်သို့ထုတ်ယူမည်နည်း။
R ရှိ lm() function မှ p-values များကို ထုတ်ယူရန် အောက်ပါနည်းလမ်းများကို အသုံးပြုနိုင်သည်။
နည်းလမ်း 1- ဆုတ်ယုတ်မှုပုံစံမှ အလုံးစုံ P တန်ဖိုးကို ထုတ်ယူပါ။
#define function to extract overall p-value of model overall_p <- function (my_model) { f <- summary(my_model)$fstatistic p <- pf(f[1],f[2],f[3],lower. tail =F) attributes(p) <- NULL return (p) } #extract overall p-value of model overall_p(model)
Method 2- regression coefficients အတွက် တစ်ဦးချင်းစီ P တန်ဖိုးများကို ထုတ်ယူပါ။
summary(model)$coefficients[,4]
အောက်ဖော်ပြပါ ဥပမာသည် ဤနည်းလမ်းများကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ- R တွင် lm() မှ P တန်ဖိုးများကို ထုတ်ယူပါ။
R တွင် အောက်ပါ multiple linear regression model နှင့် ကိုက်ညီသည်ဆိုပါစို့။
#create data frame df <- data. frame (rating=c(67, 75, 79, 85, 90, 96, 97), points=c(8, 12, 16, 15, 22, 28, 24), assists=c(4, 6, 6, 5, 3, 8, 7), rebounds=c(1, 4, 3, 3, 2, 6, 7)) #fit multiple linear regression model model <- lm(rating ~ points + assists + rebounds, data=df)
ဆုတ်ယုတ်မှုပုံစံ၏ အကျဉ်းချုပ်အပြည့်အစုံကိုပြသရန် summary() လုပ်ဆောင်ချက်ကို ကျွန်ုပ်တို့အသုံးပြုနိုင်သည်-
#view model summary
summary(model)
Call:
lm(formula = rating ~ points + assists + rebounds, data = df)
Residuals:
1 2 3 4 5 6 7
-1.5902 -1.7181 0.2413 4.8597 -1.0201 -0.6082 -0.1644
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 66.4355 6.6932 9.926 0.00218 **
points 1.2152 0.2788 4.359 0.02232 *
assists -2.5968 1.6263 -1.597 0.20860
rebounds 2.8202 1.6118 1.750 0.17847
---
Significant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.193 on 3 degrees of freedom
Multiple R-squared: 0.9589, Adjusted R-squared: 0.9179
F-statistic: 23.35 on 3 and 3 DF, p-value: 0.01396
ရလဒ်၏အောက်ခြေတွင်၊ regression model ၏ စုစုပေါင်း p-value သည် 0.01396 ဖြစ်သည်ကို တွေ့နိုင်ပါသည်။
ကျွန်ုပ်တို့သည် ဤ p-တန်ဖိုးကို မော်ဒယ်မှ ထုတ်ယူလိုပါက၊ ထိုသို့ပြုလုပ်ရန် စိတ်ကြိုက်လုပ်ဆောင်ချက်ကို ကျွန်ုပ်တို့ သတ်မှတ်နိုင်သည်-
#define function to extract overall p-value of model overall_p <- function (my_model) { f <- summary(my_model)$fstatistic p <- pf(f[1],f[2],f[3],lower. tail =F) attributes(p) <- NULL return (p) } #extract overall p-value of model overall_p(model) [1] 0.01395572
လုပ်ဆောင်ချက်သည် အထက်ဖော်ပြပါ မော်ဒယ်အထွက်ကဲ့သို့ p-value ကို ပြန်ပေးကြောင်း သတိပြုပါ။
မော်ဒယ်မှ တစ်ဦးချင်းစီ ဆုတ်ယုတ်မှုကိန်းဂဏန်းများအတွက် p-တန်ဖိုးများကို ထုတ်ယူရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။
#extract p-values for individual regression coefficients in model
summary(model)$coefficients[,4]
(Intercept) points assists rebounds
0.002175313 0.022315418 0.208600183 0.178471275
ဤနေရာတွင် ပြသထားသော p-တန်ဖိုးများသည် အထက်ဖော်ပြပါ ဆုတ်ယုတ်မှုအထွက်ရှိ Pr(> |t|) ကော်လံရှိ ၎င်းတို့နှင့် သက်ဆိုင်ကြောင်း သတိပြုပါ။
ဆက်စပ်- R-Squared ကို R ရှိ lm() လုပ်ဆောင်ချက်မှ မည်သို့ထုတ်ယူရမည်နည်း။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R တွင် ရိုးရှင်းသော linear regression လုပ်နည်း
R တွင် linear regression အများအပြားလုပ်ဆောင်နည်း
R တွင်ကျန်ရှိသောကွက်ကွက်ဖန်တီးနည်း