R ဖြင့် chi-square ဖြန့်ဝေမှုကို လွယ်ကူစွာ ဘယ်လိုဆွဲမလဲ။
R တွင် Chi-square ဖြန့်ဖြူးမှုအတွက် သိပ်သည်းဆကွက်ကွက်ဖန်တီးရန်၊ အောက်ပါလုပ်ဆောင်ချက်များကို ကျွန်ုပ်တို့အသုံးပြုနိုင်သည်-
- ဖြစ်နိုင်ခြေသိပ်သည်းဆလုပ်ဆောင်ချက်ကို ဖန်တီးရန် dchisq()
- ဖြစ်နိုင်ခြေသိပ်သည်းဆလုပ်ဆောင်ချက်ကို ချရန် Curve()
ကွက်ကွက်ဖန်တီးရန် ကျွန်ုပ်တို့လုပ်ဆောင်ရမည့်အရာမှာ dchisq() အတွက် လွတ်လပ်မှုဒီဂရီ အပြင် curve() အတွက် အထွက် နှင့် နောက်ပြန် အမှတ်များကို သတ်မှတ်ပေးခြင်းဖြစ်သည်။
ဥပမာအားဖြင့်၊ အောက်ပါကုဒ်သည် ကွက်ကွက်၏ x ဝင်ရိုး 0 နှင့် 40 ကြားတွင် လွတ်လပ်မှု 10 ဒီဂရီဖြင့် Chi-square ဖြန့်ဝေမှုအတွက် သိပ်သည်းဆကွက်ကွက်ဖန်တီးပုံကို သရုပ်ဖော်သည်-
curve(dchisq(x, df = 10), from = 0, to = 40)
သိပ်သည်းဆကို တည်းဖြတ်ခြင်း။
ခေါင်းစဉ်တစ်ခုထည့်ခြင်း၊ Y ဝင်ရိုးအညွှန်းကိုပြောင်းခြင်း၊ မျဉ်းအကျယ်ကိုတိုးမြှင့်ခြင်းနှင့် လိုင်းအရောင်ပြောင်းလဲခြင်းဖြင့် သိပ်သည်းဆကွက်ကွက်ကို တည်းဖြတ်နိုင်သည်-
curve(dchisq(x, df = 10), from = 0, to = 40, main = 'Chi-Square Distribution (df = 10)', #add title ylab = 'Density', #change y-axis label lwd = 2, #increase line width to 2 col = 'steelblue') #change line color to steelblue
သိပ်သည်းဆကို ဖြည့်ချမယ်။
သိပ်သည်းဆကွက်ကွက်ဖန်တီးခြင်းအပြင်၊ အစနှင့်အဆုံးတန်ဖိုးအပေါ်အခြေခံ၍ polygon() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ ကွက်ကွက်၏အစိတ်အပိုင်းကို ဖြည့်စွက်နိုင်ပါသည်။
အောက်ပါကုဒ်သည် 10 နှင့် 40 ကြားရှိ x တန်ဖိုးများအတွက် ကွက်ကွက်၏ သိပ်သည်းဆအပိုင်းကို မည်သို့ဖြည့်စွက်ရမည်ကို သရုပ်ပြသည်-
#create density curve curve(dchisq(x, df = 10), from = 0, to = 40, main = 'Chi-Square Distribution (df = 10)', ylab = 'Density', lwd = 2) #create vector of x values x_vector <- seq(10, 40) #create vector of chi-square density values p_vector <- dchisq(x_vector, df = 10) #fill in portion of the density plot from 0 to 40 polygon(c(x_vector, rev(x_vector)), c(p_vector, rep(0, length(p_vector))), col = adjustcolor('red', alpha=0.3), border = NA)
အောက်ပါကုဒ်သည် 0 နှင့် 10 ကြားရှိ x တန်ဖိုးများအတွက် ကွက်ကွက်၏ သိပ်သည်းဆအပိုင်းကို မည်သို့ဖြည့်စွက်ရမည်ကို သရုပ်ပြသည်-
#create density curve curve(dchisq(x, df = 10), from = 0, to = 40, main = 'Chi-Square Distribution (df = 10)', ylab = 'Density', lwd = 2) #create vector of x values x_vector <- seq( 0, 10 ) #create vector of chi-square density values p_vector <- dchisq(x_vector, df = 10) #fill in portion of the density plot from 0 to 10 polygon(c(x_vector, rev(x_vector)), c(p_vector, rep(0, length(p_vector))), col = adjustcolor('red', alpha=0.3), border = NA)
အောက်ဖော်ပြပါ ကုဒ်သည် ဖြန့်ဖြူးမှု၏ အလယ်ပိုင်း 95% ပြင်ပတွင် x-တန်ဖိုးများအတွက် သိပ်သည်းဆကွက်ကွက်၏ အပိုင်းကို မည်ကဲ့သို့ ဖြည့်စွက်ရမည်ကို ဖော်ပြသည်-
#create density curve curve(dchisq(x, df = 10), from = 0, to = 40, main = 'Chi-Square Distribution (df = 10)', ylab = 'Density', lwd = 2) #find upper and lower values for middle 95% of distribution lower95 <- qchisq(.025, 10) upper95 <- qchisq(.975, 10) #create vector of x values x_lower95 <- seq(0, lower95) #create vector of chi-square density values p_lower95 <- dchisq(x_lower95, df = 10) #fill in portion of the density plot from 0 to lower 95% value polygon(c(x_lower95, rev(x_lower95)), c(p_lower95, rep(0, length(p_lower95))), col = adjustcolor('red', alpha=0.3), border = NA) #create vector of x values x_upper95 <- seq(upper95, 40) #create vector of chi-square density values p_upper95 <- dchisq(x_upper95, df = 10) #fill in portion of the density plot for upper 95% value to end of plot polygon(c(x_upper95, rev(x_upper95)), c(p_upper95, rep(0, length(p_upper95))), col = adjustcolor('red', alpha=0.3), border = NA)
နောက်ဆုံးတွင်၊ အောက်ပါကုဒ်သည် ဖြန့်ဖြူးမှု၏ 95% အလယ်ဗဟို အတွင်း ကျသော x-တန်ဖိုးများအတွက် သိပ်သည်းဆကွက်ကွက်၏အပိုင်းကို မည်သို့ဖြည့်စွက်ရမည်ကို ဖော်ပြသည်-
#create density curve curve(dchisq(x, df = 10), from = 0, to = 40, main = 'Chi-Square Distribution (df = 10)', ylab = 'Density', lwd = 2) #find upper and lower values for middle 95% of distribution lower95 <- qchisq(.025, 10) upper95 <- qchisq(.975, 10) #create vector of x values x_vector <- seq(lower95, upper95) #create vector of chi-square density values p_vector <- dchisq(x_vector, df = 10) #fill in density plot polygon(c(x_vector, rev(x_vector)), c(p_vector, rep(0, length(p_vector))), col = adjustcolor('red', alpha=0.3), border = NA)