R တွင် ပုံမှန်ဖြန့်ဖြူးနည်း
R တွင် သာမာန်ဖြန့်ဝေမှု တစ်ခုကို စီစဉ်ရန်၊ ကျွန်ုပ်တို့သည် အခြေခံ R ကိုသုံးနိုင်သည် သို့မဟုတ် ggplot2 ကဲ့သို့ ပိုမိုခေတ်မီသော အထုပ်တစ်ခုကို ထည့်သွင်းနိုင်သည်။
BaseR ကိုအသုံးပြုခြင်း။
ဤသည်မှာ Base R ကို အသုံးပြု၍ ပုံမှန်ဖြန့်ဝေကွက်တစ်ခု ဖန်တီးခြင်း၏ ဥပမာ သုံးခုဖြစ်သည်။
ဥပမာ 1- ပျမ်းမျှ = 0 နှင့် စံသွေဖည်မှု = 1 ဖြင့် ပုံမှန်ဖြန့်ဖြူးသည်။
ပျမ်းမျှ = 0 နှင့် စံသွေဖည်မှု = 1 ဖြင့် ပုံမှန်ဖြန့်ဖြူးကွက်တစ်ခုကို ဖန်တီးရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်ပါသည်။
#Create a sequence of 100 equally spaced numbers between -4 and 4 x <- seq(-4, 4, length=100) #create a vector of values that shows the height of the probability distribution #for each value in x y <- dnorm(x) #plot x and y as a scatterplot with connected lines (type = "l") and add #an x-axis with custom labels plot(x,y, type = "l", lwd = 2, axes = FALSE, xlab = "", ylab = "") axis(1, at = -3:3, labels = c("-3s", "-2s", "-1s", "mean", "1s", "2s", "3s"))
၎င်းသည် အောက်ပါကွက်ကွက်ကို ထုတ်ပေးသည်-
ဥပမာ 2- ပျမ်းမျှ = 0 နှင့် ပုံမှန်သွေဖည်မှု = 1 (ကုဒ်နည်း)
x နှင့် y ကိုမသတ်မှတ်ဘဲ ပုံမှန်ဖြန့်ဝေကွက်တစ်ခုကိုလည်း ဖန်တီးနိုင်ပြီး၊ အောက်ပါကုဒ်ကိုအသုံးပြု၍ “ မျဉ်းကွေး” လုပ်ဆောင်ချက်ကို ရိုးရိုးရှင်းရှင်း အသုံးပြုနိုင်သည်။
curve(dnorm, -3.5, 3.5, lwd=2, axes = FALSE, xlab = "", ylab = "") axis(1, at = -3:3, labels = c("-3s", "-2s", "-1s", "mean", "1s", "2s", "3s"))
၎င်းသည် အတိအကျတူညီသော ဇာတ်ကွက်ကို ထုတ်ပေးသည်-
ဥပမာ 3- Custom Mean နှင့် Standard Deviation ဖြင့် ပုံမှန်ဖြန့်ဝေခြင်း။
အသုံးပြုသူသတ်မှတ်ထားသော ဆိုလိုရင်းနှင့် စံသွေဖည်မှုဖြင့် ပုံမှန်ဖြန့်ဝေကွက်တစ်ခုကို ဖန်တီးရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်ပါသည်။
#define population mean and standard deviation population_mean <- 50 population_sd <- 5 #define upper and lower bound lower_bound <- population_mean - population_sd upper_bound <- population_mean + population_sd #Create a sequence of 1000 x values based on population mean and standard deviation x <- seq(-4, 4, length = 1000) * population_sd + population_mean #create a vector of values that shows the height of the probability distribution #for each value in x y <- dnorm(x, population_mean, population_sd) #plot normal distribution with customized x-axis labels plot(x,y, type = "l", lwd = 2, axes = FALSE, xlab = "", ylab = "") sd_axis_bounds = 5 axis_bounds <- seq(-sd_axis_bounds * population_sd + population_mean, sd_axis_bounds * population_sd + population_mean, by = population_sd) axis(side = 1, at = axis_bounds, pos = 0)
၎င်းသည် အောက်ပါကွက်ကွက်ကို ထုတ်ပေးသည်-
ggplot2 ကိုအသုံးပြုခြင်း။
R တွင် ပုံမှန်ဖြန့်ဝေကွက်တစ်ခုကို ဖန်တီးရန် အခြားနည်းလမ်းမှာ ggplot2 ပက်ကေ့ဂျ်ကို အသုံးပြုခြင်းဖြစ်သည်။ ဤသည်မှာ ggplot2 ကိုအသုံးပြု၍ ပုံမှန်ဖြန့်ဖြူးကွက်ဖန်တီးခြင်း၏နမူနာနှစ်ခုဖြစ်သည်။
ဥပမာ 1- ပျမ်းမျှ = 0 နှင့် စံသွေဖည်မှု = 1 ဖြင့် ပုံမှန်ဖြန့်ဖြူးသည်။
ပျမ်းမျှ = 0 နှင့် စံသွေဖည်မှု = 1 ဖြင့် ပုံမှန်ဖြန့်ဖြူးကွက်တစ်ခုကို ဖန်တီးရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်ပါသည်။
#install (if not already installed) and load ggplot2 if(!(require(ggplot2))){install.packages('ggplot2')} #generate a normal distribution plot ggplot(data.frame(x = c(-4, 4)), aes(x = x)) + stat_function(fun = dnorm)
၎င်းသည် အောက်ပါကွက်ကွက်ကို ထုတ်ပေးသည်-
ဥပမာ 2- ‘mtcars’ ဒေတာအတွဲကို အသုံးပြု၍ ပုံမှန်ဖြန့်ဝေခြင်း။
အောက်ဖော်ပြပါ ကုဒ်သည် mtcars မြှုပ်သွင်းထားသော R ဒေတာအတွဲတွင် တစ်ဂါလံလျှင် မိုင်နှုန်း အတွက် ပုံမှန်ဖြန့်ဝေမှုကို ဖန်တီးနည်းကို သရုပ်ပြသည်-
ggplot(mtcars, aes(x = mpg)) + stat_function( fun = dnorm, args = with(mtcars, c(mean = mean(mpg), sd = sd(mpg))) ) + scale_x_continuous("Miles per gallon")
၎င်းသည် အောက်ပါကွက်ကွက်ကို ထုတ်ပေးသည်-