我試圖得到這樣一幅畫面:?(三角形分佈,b和c) R:如何創建具有不同類型的數據的箱線圖
在圖片,參數,它們的分佈和參數的置信區間是基於原始數據集的,而模擬的是通過參數和非參數引導生成的。如何在R中繪製這樣的圖片?你能舉一個這樣的簡單例子嗎?非常感謝你!
這是我的代碼。
x1<-c(1300,541,441,35,278,167,276,159,126,170,251.3,155.84,187.01,850)
x2<-c(694,901,25,500,42,2.2,7.86,50)
x3<-c(2800,66.5,420,260,50,370,17)
x4<-c(12,3.9,10,28,84,138,6.65)
y1<-log10(x1)
y2<-log10(x2)
y3<-log10(x3)
y4<-log10(x4)
#Part 1 (Input the data) In this part, I have calculated the parameters (a and b) and the confidence interval (a and b) by MLE and PB-MLE with different data sets(x1 to x4)
#To calculate the parameters (a and b) with data sets x1
y.n<-length(y1)
y.location<-mean(y1)
y.var<-(y.n-1)/y.n*var(y1)
y.scale<-sqrt(3*y.var)/pi
library(stats4)
ll.logis<-function(location=y.location,scale=y.scale){-sum(dlogis(y1,location,scale,log=TRUE))}
fit.mle<-mle(ll.logis,method="Nelder-Mead")
a1_mle<-coef(fit.mle)[1]
b1_mle<-coef(fit.mle)[2]
summary(a1_mle)# To calculate the parameters (a)
summary(b1_mle)# To calculate the parameters (b)
confint(fit.mle)# To calculate the confidence interval (a and b) by MLE
# load fitdistrplus package for using fitdist function
library(fitdistrplus)
# fit logistic distribution using MLE method
x1.logis <- fitdist(y1, "logis", method="mle")
A<- bootdist(x1.logis, bootmethod="param", niter=1001)
summary(A) # To calculate the parameters (a and b) and the confidence interval (a and b) by parametric bootstrap
a <- A$estim
a1<-c(a$location)
b1<-c(a$scale)
#To calculate the parameters (a and b) with data sets x2
y.n<-length(y2)
y.location<-mean(y2)
y.var<-(y.n-1)/y.n*var(y2)
y.scale<-sqrt(3*y.var)/pi
library(stats4)
ll.logis<-function(location=y.location,scale=y.scale){-sum(dlogis(y2,location,scale,log=TRUE))}
fit.mle<-mle(ll.logis,method="Nelder-Mead")
a2_mle<-coef(fit.mle)[1]
b2_mle<-coef(fit.mle)[2]
summary(a2_mle)# To calculate the parameters (a)
summary(b2_mle)# To calculate the parameters (b)
confint(fit.mle)# To calculate the confidence interval (a and b) by MLE
x2.logis <- fitdist(y2, "logis", method="mle")
B<- bootdist(x2.logis, bootmethod="param", niter=1001)
summary(B)
b <- B$estim
a2<-c(b$location)
b2<-c(b$scale)
#To calculate the parameters (a and b) with data sets x3
y.n<-length(y3)
y.location<-mean(y3)
y.var<-(y.n-1)/y.n*var(y3)
y.scale<-sqrt(3*y.var)/pi
library(stats4)
ll.logis<-function(location=y.location,scale=y.scale){-sum(dlogis(y3,location,scale,log=TRUE))}
fit.mle<-mle(ll.logis,method="Nelder-Mead")
a3_mle<-coef(fit.mle)[1]
b3_mle<-coef(fit.mle)[2]
summary(a3_mle)# To calculate the parameters (a)
summary(b3_mle)# To calculate the parameters (b)
confint(fit.mle)# To calculate the confidence interval (a and b) by MLE
x3.logis <- fitdist(y3, "logis", method="mle")
C <- bootdist(x3.logis, bootmethod="param", niter=1001)
summary(C)
c<- C$estim
a3<-c(c$location)
b3<-c(c$scale)
#To calculate the parameters (a and b) with data sets x4
y.n<-length(y4)
y.location<-mean(y4)
y.var<-(y.n-1)/y.n*var(y4)
y.scale<-sqrt(3*y.var)/pi
library(stats4)
ll.logis<-function(location=y.location,scale=y.scale){-sum(dlogis(y4,location,scale,log=TRUE))}
fit.mle<-mle(ll.logis,method="Nelder-Mead")
a4_mle<-coef(fit.mle)[1]
b4_mle<-coef(fit.mle)[2]
summary(a4_mle)# To calculate the parameters (a)
summary(b4_mle)# To calculate the parameters (b)
confint(fit.mle)# To calculate the confidence interval (a and b) by MLE
x4.logis <- fitdist(y4, "logis", method="mle")
D <- bootdist(x4.logis, bootmethod="param", niter=1001)
summary(D)
d <- D$estim
a4<-c(d$location)
b4<-c(d$scale)
請提供[可重現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),以方便我們爲您提供幫助。目前還不清楚你的問題到底是什麼。您是否無法生成要繪製的數字,或者您是否擁有所有的數字以及要執行的情節?如果後者,給我們一個你的號碼的例子格式化。告訴我們你已經嘗試了什麼,並縮小你的具體問題。這樣的問題太寬泛 –
謝謝你的慷慨評論。我認爲我的問題是後者。我現在添加我的代碼鈴聲。在這段代碼中,我已經通過原始數據集和參數引導計算了參數(a和b)和置信區間。 –