如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
R复习提纲截取了些东西,有需要的可以下来看看。——何斌会用R写牛顿算法求极大似然估计及置信区间。Newtons<-function(fun,x,ep=1e-5,it_max=100){index<-0;k<-1while(k<=it_max){x1<-x;obj<-fun(x);x<-x-solve(obj$J,obj$f);norm<-sqrt((x-x1)%*%(x-x1))if(norm<ep){index<-1;break}k<-k+1}obj<-fun(x);list(root=x,it=k,index=index,FunVal=obj$f)}funs<-function(x){f<-c(x[1]^2+x[2]^2-5,(x[1]+1)*x[2]-(3*x[1]+1))J<-matrix(c(2*x[1],2*x[2],x[2]-3,x[1]+1),nrow=2,byrow=T)list(f=f,J=J)}Newtons(funs,c(0,1))interval_estimate1<-function(x,sigma=-1,alpha=0.05){n<-length(x);xb<-mean(x)if(sigma>=0){tmp<-sigma/sqrt(n)*qnorm(1-alpha/2);df<-n}else{tmp<-sd(x)/sqrt(n)*qt(1-alpha/2,n-1);df<-n-1}data.frame(mean=xb,df=df,a=xb-tmp,b=xb+tmp)}会计算随机变量的函数的密度函数和相关的事件概率,会求相应的模型参数的mlex<-rcauchy(1000,1)f<-function(p)sum((x-p)/(1+(x-p)^2))out<-uniroot(f,c(0,5))loglike<-function(p)sum(log(1+(x-p)^2))out<-optimize(loglike,c(0,5))会使用正确的统计检验方法来得到合理的结果。包括t.test,Wilcox.test,fisher.test,chisq.test,binom.test,ks.test,mcnemar.test,cor.test,var.test的使用条件。X<-c(10.1,10,9.8,10.5,9.7,10.1,9.9,10.2,10.3,9.9)interval_estimate1(X)>t.test(X)OneSamplet-testdata:Xt=131.5854,df=9,p-value=4.296e-16alternativehypothesis:truemeanisnotequalto095percentconfidenceinterval:9.87722510.222775sampleestimates:meanofx10.05x<-rnorm(12,501.1,2.4)y<-rnorm(17,499.7,4.7)interval_estimate2(x,y,var.equal=TRUE)interval_estimate2(x,y)>t.test(x,y)WelchTwoSamplet-testdata:xandyt=0.1353,df=23.949,p-value=0.8935alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-2.6158422.982820sampleestimates:meanofxmeanofy499.4612499.2777t.test(x,y,var.equal=TRUE)X<-c(11.3,15.0,15.0,13.5,12.8,10.0,11.0,12.0,13.0,12.3)Y<-c(14.0,13.8,14.0,13.5,13.5,12.0,14.7,11.4,13.8,12.0)t.test(X-Y)X<-scan()137.0140.0138.3139.0144.3139.1141.7137.3133.5138.2141.1139.2136.5136.5135.6138.0140.9140.6136.3134.1wilcox.test(X,mu=140,alternative="less",exact=FALSE,correct=FALSE,conf.int=TRUE)x<-c(459,367,303,392,