ကွက်များသို့ မျဉ်းဖြောင့်များထည့်ရန် r တွင် aline() ကိုအသုံးပြုနည်း
R ရှိ abline() လုပ်ဆောင်ချက်ကို R ရှိကွက်တစ်ခုသို့ တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသောမျဉ်းဖြောင့်များထည့်ရန် အသုံးပြုနိုင်သည်။
ဤလုပ်ဆောင်ချက်သည် အောက်ပါ syntax ကိုအသုံးပြုသည်-
abline(a=NULL၊ b=NULL၊ h=NULL၊ v=NULL၊ …)
ရွှေ-
- a, b: မျဉ်း၏ဇာစ်မြစ်နှင့် လျှောစောက်ကို သတ်မှတ်သော ထူးခြားသောတန်ဖိုးများ
- h- အလျားလိုက်မျဉ်းအတွက် y တန်ဖိုး
- v- ဒေါင်လိုက်မျဉ်းအတွက် x တန်ဖိုး
အောက်ဖော်ပြပါ ဥပမာများသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
အလျားလိုက်လိုင်းများထည့်နည်း
R တွင် ကွက်ကွက်တစ်ခုသို့ အလျားလိုက်မျဉ်းကိုထည့်ခြင်းအတွက် အခြေခံကုဒ်မှာ abline(h = အချို့တန်ဖိုး)
ဒေတာအတွဲတစ်ခုတွင် x နှင့် y တို့၏တန်ဖိုးများကိုပြသသော အောက်ပါ scatterplot ရှိသည်ဆိုပါစို့။
#define dataset data <- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11), y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41)) #plot x and y values in dataset plot(data$x, data$y, pch = 16)
တန်ဖိုး y = 20 တွင် အလျားလိုက်မျဉ်းတစ်ခုကို ထည့်ရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်သည်။
abline(h = 20, col = 'coral2', lwd = 2)
အောက်ဖော်ပြပါ ကုဒ်သည် y ၏ ပျမ်းမျှတန်ဖိုးနှင့် ပျမ်းမျှတန်ဖိုး အထက်နှင့် ပျမ်းမျှတန်ဖိုးအောက် စံသွေဖည်သည့် စံသွေဖည်မှုတစ်ခုအား y ၏ ပျမ်းမျှတန်ဖိုးသို့ မည်သို့ထည့်ရမည်ကို အောက်ပါကုဒ်က ဖော်ပြသည်-
#create scatterplot for x and y plot(data$x, data$y, pch = 16) #create horizontal line at mean value of y abline(h = mean(data$y), lwd = 2) #create horizontal lines at one standard deviation above and below the mean value abline(h = mean(data$y) + sd(data$y), col = 'steelblue', lwd = 3, lty = 2) abline(h = mean(data$y) - sd(data$y), col = 'steelblue', lwd = 3, lty = 2)
ဒေါင်လိုက်လိုင်းများထည့်နည်း
R တွင် ကွက်ကွက်တစ်ခုသို့ ဒေါင်လိုက်မျဉ်းတစ်ခုထည့်ခြင်းအတွက် အခြေခံကုဒ်မှာ abline(v = အချို့တန်ဖိုး)
အောက်ပါကုဒ်သည် ဒေါင်လိုက်မျဉ်းတစ်ကြောင်းကို ဟီစတိုဂရမ်တစ်ခုရှိ ပျမ်းမျှတန်ဖိုးသို့ ဒေါင်လိုက်ထည့်နည်းကို သရုပ်ပြသည်-
#make this example reproducible set.seed(0) #create dataset with 1000 random values normally distributed with mean = 10, sd = 2 data <- rnorm(1000, mean = 10, sd = 2) #create histogram of data values hist(data, col = 'steelblue') #draw a vertical dashed line at the mean value abline(v = mean(data), lwd = 3, lty = 2)
ဆုတ်ယုတ်မှုလိုင်းများထည့်နည်း
R တွင်ကွက်ကွက်တစ်ခုသို့ရိုးရှင်းသောမျဉ်းကြောင်းဆုတ်ယုတ်မှုမျဉ်းကိုထည့်ခြင်းအတွက်အခြေခံကုဒ်မှာ- abline(မော်ဒယ်)
အောက်ဖော်ပြပါ ကုဒ်သည် ကွက်လပ်တစ်ခုသို့ တပ်ဆင်ထားသော မျဉ်းကြောင်းပြန်ဆုတ်မှုမျဉ်းကို ဖြန့်ကျက်ပုံကို သရုပ်ပြသည်-
#define dataset data <- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11), y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41)) #create scatterplot of x and y values plot(data$x, data$y, pch = 16) #fit a linear regression model to the data reg_model <- lm(y ~ x, data = data) #add the fitted regression line to the scatterplot abline(reg_model, col="steelblue")
abline() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ ဒေတာနှင့် ရိုးရှင်းသော linear regression line တစ်ခုနှင့် ကိုက်ညီရန် ကြားဖြတ်နှင့် slope အတွက် တန်ဖိုးတစ်ခု လိုအပ်ကြောင်း သတိပြုပါ။
ထို့ကြောင့်၊ regression line ကိုထည့်ရန် abline() ကိုသုံးရန် အခြားနည်းလမ်းမှာ regression model ၏ မူရင်းနှင့် slope coefficients ကို ပြတ်သားစွာ သတ်မှတ်ရန်ဖြစ်သည် ။
#define dataset data <- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11), y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41)) #create scatterplot of x and y values plot(data$x, data$y, pch = 16) #fit a linear regression model to the data reg_model <- lm(y ~ x, data = data) #define intercept and slope values a <- coefficients(reg_model)[1] #intercept b <- coefficients(reg_model)[2] #slope #add the fitted regression line to the scatterplot abline(a=a, b=b, col="steelblue")
၎င်းသည် ယခင်ကဲ့သို့ တူညီသောလိုင်းကို ထုတ်လုပ်ကြောင်း သတိပြုပါ။
နောက်ထပ် R သင်ခန်းစာများကို ဤစာမျက်နှာတွင် သင်တွေ့နိုင်ပါသည်။