# Prova finale Lab IS 20-21 # 1 luglio 21 # Es. 1 rm(list = ls()) x=c(2,4,1,6,3) n=length(x) t=sum(x) th1=2.9 th2=3.3 L1=exp(-t/th1)/(th1^n) L2=exp(-t/th2)/(th2^n) L1/L2 # 0.97 # Es. 2 rm(list = ls()) n=20 s=40 m=s/n m q=0.8 k=sqrt(-2*log(q)) k L=m-k*m/sqrt(n) U=m+k*m/sqrt(n) L U # 1.7 2.3 # Es. 3 rm(list = ls()) x=c(-1,0.004,1.03,0.83,0.26, 0.21, -0.32, 0.9, -0.6, 1.8) n=length(x) n sig=1 m=mean(x) m # 0.31 L=m-1.96*sig/sqrt(n) U=m+1.96*sig/sqrt(n) L U # -0.31 0.93 th0=0 w.oss=sqrt(n)*(m-th0)/sig w.oss # Rif se |w.oss|>1.96 w.oss>1.96 # p.value 2*pnorm(-abs(w.oss)) # 0.32 >0.05 --> accetto H0 # Es. 4 rm(list = ls()) n=15 mu=3 sig=1 M=10000 x.matr=rnorm(n*M,mu,sig) x.matr=matrix(x.matr,M,n) mediane=apply(x.matr,1,median) L=mediane-1/2 U=mediane+1/2 mean(L<=mu&U>=mu) # 0.88 # Es. 5 rm(list = ls()) n=10 M=10000 th0=0.3 th1=0.5 # sotto H0 x.matr.0=rbinom(n*M,size=1,prob=th0) x.matr.0=matrix(x.matr.0,M,n) x.vett.0=apply(x.matr.0,1,sum) # prob err 1 tipo mean(x.vett.0>3.5) # 0.346 # sotto H1 x.matr.1=rbinom(n*M,size=1,prob=th1) x.matr.1=matrix(x.matr.1,M,n) x.vett.1=apply(x.matr.1,1,sum) # pr errore 2 tipo mean(x.vett.1<3.5) # 0.169 # potenza 1-mean(x.vett.1<3.5) # 0.83