2021
05-19
05-19
R语言—自定义函数求置信区间的操作
看代码吧~#求单正态均值mu的置信区间#参数依次为置信水平alpha,正态样本x,已知总体方差(默认为未知)mu<-function(alpha,x,sigma=NA){n<-length(x)meanx<-mean(x)if(is.na(sigma)){t1<-qt(1-alpha/2,n-1)t2<-qt(1-alpha,n-1)mu11<-meanx-t1*sqrt(sum((x-meanx)^2)/(n-1))/sqrt(n)mu12<-meanx+t1*sqrt(sum((x-meanx)^2)/(n-1))/sqrt(n)mu21<-meanx+t2*sqrt(sum((x-meanx)^2)/(n...
继续阅读 >