# Prova finale LIS 1 - 2023-2024 - 30 maggio 2024 # ES 1 rm(list=ls()) al=3 be=4 pgamma(1.5,al,rate=be)-pgamma(0.5,al,rate=be) # RIS 0.614 # 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=1 sig=sqrt(sig2) # Lq q=0.8 k=sqrt(-2*log(q)) L.lik=xmed-k*sig/sqrt(n) U.lik=xmed+k*sig/sqrt(n) c(L.lik,U.lik) # RIS 2.915 3.338 # IC alpha=0.1 z=qnorm(1-alpha/2) L=xmed-z*sig/sqrt(n) U=xmed+z*sig/sqrt(n) c(L,U) # RIS 2.606 3.647 # 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.5, alternative = "two.sided", conf.level = 0.95) # RIS # stima puntuale 3.127, IC 2.410 3.843 # p-value = 0.07911 --> si accetta H0 # ES 4 rm(list=ls()) theta=3 M=100000 x.mc=rgamma(M,1,scale=theta) E.mc=mean(x.mc) y.mc=(x.mc-E.mc)^3 mu.3=mean(y.mc) mu.3 # RIS 55.950 # ES 5 rm(list=ls()) theta=3 n=7 lambda=(theta-1)/2 M=100000 x.mc=rgamma(M*n,1,scale = lambda) x.mc=matrix(x.mc,M,n) stim.mc=2*apply(x.mc,1,mean) + 1 # per MSE mean((stim.mc-theta)^2) # RIS 0.57 # ES 6 rm(list=ls()) theta=3 a=1 b=1.2 n=8 M=100000 x.mc=runif(M*n,0,theta) x.mc=matrix(x.mc,M,n) max.mc=apply(x.mc,1,max) L=a*max.mc U=b*max.mc copertura=mean(L<=theta&U>=theta) copertura # RIS 0.765 # ES 7 rm(list=ls()) n=15 theta=5 M=100000 x.mc=rpois(M*n,theta) x.mc=matrix(x.mc,M,n) mediane.mc=apply(x.mc,1,median) L=mediane.mc-1/sqrt(n) U=mediane.mc+1/sqrt(n) copertura=mean(L<=theta&U>=theta) copertura # RIS 0.500 # ES 8 rm(list=ls()) th0=3.5 th1=2.5 n=9 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) S2.H0=apply(x.mc.H0,1,var) 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