# Prova finale LIS 2 - 2023-2024 - 05 maggio 2024 # ES 1 rm(list=ls()) al=3 be=4 pbeta(0.8,al,be)-pbeta(0.5,al,be) # RIS 0.326 qbeta(0.25, al, be) # RIS 0.296 # ES 2 rm(list=ls()) dati=c(1.88, 1.72, 3.79, 4.66, 4.12, 2.86, 3.14, 3.34, 2.02, 3.74) n=length(dati) xmed=mean(dati) xmed sig2=2 sig=sqrt(sig2) # IC alpha=0.2 z=qnorm(1-alpha/2) L=xmed-z*sig/sqrt(n) U=xmed+z*sig/sqrt(n) c(L,U) # RIS 2.5. 3.7 # ES 3 rm(list=ls()) dati=c(1.88, 1.72, 3.79, 4.66, 4.12, 2.86, 3.14, 3.34, 2.02, 3.74) t.test(dati,mu=2.7, alternative = "two.sided", conf.level = 0.85) # RIS # stima puntuale 3.127, IC 2.62 3.62 # p-value = 0.21 --> si accetta H0 # ES 4 rm(list=ls()) theta=2 M=100000 x.mc=rgamma(M,1,scale=theta) y.mc=x.mc^3 mu.3=mean(y.mc) mu.3 # RIS 47.24 # ES 5 rm(list=ls()) theta=2 n=7 M=100000 x.mc=rgamma(M*n,3,scale = theta) x.mc=matrix(x.mc,M,n) stim.mc=apply(x.mc,1,mean)/3 # varianza stimatore var(stim.mc) # RIS 0.57 theta^2/(3*n) # ES 6 e 7 rm(list=ls()) theta=5 n=10 M=100000 x.mc=rgamma(M*n,3,scale=theta) x.mc=matrix(x.mc,M,n) stimatore.mc=apply(x.mc,1,mean)/3 al=0.05 L=stimatore.mc-qnorm(1-al/2)*stimatore.mc/sqrt(3*n) U=stimatore.mc+qnorm(1-al/2)*stimatore.mc/sqrt(3*n) copertura=mean(L<=theta&U>=theta) copertura # RIS 0.934 # Lungh attesa mean(U-L) # RIS 3.57 # ES 8 rm(list=ls()) th0=3.5 th1=2.5 n=30 k=2 M=100000 # sotto H0 x.mc.H0=rnorm(n*M,mean=0,sd=sqrt(th0)) x.mc.H0=matrix(x.mc.H0,M,n) x.mc.H0=x.mc.H0^2 S2.H0=apply(x.mc.H0,1,mean) prob.err.tipo1=mean(S2.H0k) prob.err.tipo2 # beta potenza=1-prob.err.tipo2 potenza # 1-beta # RIS beta=0.603 1-beta=0.396