R တွင် linearhypothesis() function ကိုအသုံးပြုနည်း
သတ်မှတ်ထားသော ဆုတ်ယုတ်မှုပုံစံတစ်ခုရှိ မျဉ်းရိုးယူဆချက်များကို စမ်းသပ်ရန် R ရှိ ကား အထုပ်မှ LinearHypothesis() လုပ်ဆောင်ချက်ကို သင်အသုံးပြုနိုင်သည်။
ဤလုပ်ဆောင်ချက်သည် အောက်ပါအခြေခံ syntax ကိုအသုံးပြုသည်-
linearHypothesis(fit, c(" var1=0 ", " var2=0 "))
ဤဥပမာတွင် fit ဟုခေါ်သော ပုံစံရှိ regression coefficients var1 နှင့် var2 တို့သည် သုညနှင့် တူညီခြင်းရှိမရှိ စမ်းသပ်သည်။
အောက်ဖော်ပြပါ ဥပမာသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ- R တွင် LinearHypothesis() လုပ်ဆောင်ချက်ကို အသုံးပြုနည်း
ကျွန်ုပ်တို့တွင် အောက်ပါဒေတာဘောင် R တွင် စာကျက်ချိန်ကြာချိန်၊ လေ့ကျင့်ရေးစာမေးပွဲအရေအတွက်နှင့် အတန်းတစ်ခန်းရှိ ကျောင်းသား 10 ဦး၏ နောက်ဆုံးစာမေးပွဲရမှတ်တို့ကို ပြသသည်ဆိုပါစို့။
#create data frame df <- data.frame(score=c(77, 79, 84, 85, 88, 99, 95, 90, 92, 94), hours=c(1, 1, 2, 3, 2, 4, 4, 2, 3, 3), prac_exams=c(2, 4, 4, 2, 4, 5, 4, 3, 2, 1)) #view data frame df score hours prac_exams 1 77 1 2 2 79 1 4 3 84 2 4 4 85 3 2 5 88 2 4 6 99 4 5 7 95 4 4 8 90 2 3 9 92 3 2 10 94 3 1
ယခု ကျွန်ုပ်တို့သည် R တွင် အောက်ပါ multiple linear regression model ကို ကိုက်ညီလိုသည်ဆိုပါစို့။
စာမေးပွဲရမှတ် = β 0 + β 1 (နာရီ) + β 2 (လက်တွေ့စာမေးပွဲများ)
ဤမော်ဒယ်ကို လိုက်လျောညီထွေဖြစ်အောင် lm() လုပ်ဆောင်ချက်ကို အသုံးပြုနိုင်ပါသည်။
#fit multiple linear regression model fit <- lm(score ~ hours + prac_exams, data=df) #view summary of model summary(fit) Call: lm(formula = score ~ hours + prac_exams, data = df) Residuals: Min 1Q Median 3Q Max -5.8366 -2.0875 0.1381 2.0652 4.6381 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 72.7393 3.9455 18.436 3.42e-07 *** hours 5.8093 1.1161 5.205 0.00125 ** prac_exams 0.3346 0.9369 0.357 0.73150 --- Significant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.59 on 7 degrees of freedom Multiple R-squared: 0.8004, Adjusted R-squared: 0.7434 F-statistic: 14.03 on 2 and 7 DF, p-value: 0.003553
ယခု ကျွန်ုပ်တို့သည် နာရီ ကိန်းဂဏန်းနှင့် prac_exam နှစ်ခုလုံး သုညဟုတ်မဟုတ် စမ်းသပ်လိုသည်ဆိုပါစို့။
ဒါကိုလုပ်ဖို့ LinearHypothesis() function ကိုသုံးနိုင်ပါတယ်။
library (car) #perform hypothesis test for hours=0 and prac_exams=0 linearHypothesis(fit, c(" hours=0 ", " prac_exams=0 ")) Linear hypothesis testing Hypothesis: hours = 0 prac_exams = 0 Model 1: restricted model Model 2: score ~ hours + prac_exams Res.Df RSS Df Sum of Sq F Pr(>F) 1 9 452.10 2 7 90.24 2 361.86 14.035 0.003553 ** --- Significant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
သီအိုရီစစ်ဆေးမှုသည် အောက်ပါတန်ဖိုးများကို ပြန်ပေးသည်-
- F-test ကိန်းဂဏန်း : 14.035
- p-တန်ဖိုး : .003553
ဤသီအိုရီစမ်းသပ်မှုတွင် အောက်ပါ null နှင့် အခြားအခြားသော ယူဆချက်များကို အသုံးပြုသည်-
- H 0 : ဆုတ်ယုတ်မှုကိန်းဂဏန်းနှစ်ခုလုံးသည် သုညနှင့်ညီသည်။
- H A : အနည်းဆုံး regression coefficient တစ်ခုသည် သုညနှင့် မညီမျှပါ။
စစ်ဆေးမှု၏ p-value (0.003553) သည် 0.05 ထက်နည်းသောကြောင့်၊ null hypothesis ကို ငြင်းပယ်ပါသည်။
တစ်နည်းဆိုရသော် နာရီ နှင့် prac_exam နှစ်ခုလုံးသည် သုညနှင့် ညီမျှသည်ဟု ဆိုရန် လုံလောက်သော အထောက်အထား မရှိပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် linear regression အကြောင်း ထပ်လောင်းအချက်အလက်များကို ပေးဆောင်သည်-
R တွင် regression output ကို အဓိပ္ပာယ်ဖွင့်ဆိုပုံ
R တွင် ရိုးရှင်းသော linear regression လုပ်နည်း
R တွင် linear regression အများအပြားလုပ်ဆောင်နည်း
R တွင် logistic regression ကို မည်သို့လုပ်ဆောင်ရမည်နည်း