# LIS 24-25 # Laboratorio 2 - 06 marzo 2025 # Variabili aleatorie; funzione di verosimiglianza (fdv) # Esercizio 1 curve(dexp(x,rate=1/0.5),from=0,to=5) curve(dexp(x,rate=1),add=T,lty=2) curve(dexp(x,rate=1/2),add=T,lty=3) # Esercizio 2 curve(dexp(x,rate=0.5),from=0,to=2,ylim=c(0,2)) curve(dexp(x,rate=1),add=T,lty=2) curve(dexp(x,rate=2),add=T,lty=3) # Esercizio 3 curve(dgamma(x,shape=1,scale=2),from=0,to=10) curve(dgamma(x,shape=2,scale=2),add=T,lty=2) curve(dgamma(x,shape=3,scale=2),add=T,lty=3) curve(dgamma(x,shape=5,scale=1),add=T,lty=4) # Esercizio 4 curve(dnorm(x),from=-3,to=3) pnorm(-1) # Esercizio 5 pnorm(3,1,sqrt(2))-pnorm(-2,1,sqrt(2)) # 0.904 # Esercizio 6 # help(dchisq) curve(dchisq(x,0.5),xlim=c(0,20),ylim=c(0,0.5)) curve(dchisq(x,3),add=TRUE, lty=2) curve(dchisq(x,5), add=TRUE, lty=3) curve(dchisq(x,10), add=TRUE, lty=4) # Esercizio 7 xn=c(1,1,0,0,0,1,1) fi=dbinom(xn,size=1,prob=0.4) prod(fi) # oppure tn=sum(xn) n=length(xn) th=0.4 th^tn*(1-th)^(n-tn) # 0.0055 # per n=15 e tn=10 tn=10 n=15 th=0.4 th^tn*(1-th)^(n-tn) # circa 0 #Esercizio 8 xn=c(0.5,2,1) n=length(xn) fi=dnorm(xn,mean=1,sd=sqrt(2)) prod(fi) # 0.016 # Esercizio 9 xn=c(1,1,0,1,0) n=length(xn) th1=0.1 th2=0.9 tn=sum(xn) Lik1=(th1^tn)*(1-th1)^(n-tn) Lik1 # 0.0008 Lik2=(th2^tn)*(1-th2)^(n-tn) Lik2 # 0.0079 # rapporto Lik1/Lik2 # 0.11 # Esercizio 10 n=50 tn=30 th1=0.1 th2=0.9 Lik1=(th1^tn)*(1-th1)^(n-tn) Lik1 Lik2=(th2^tn)*(1-th2)^(n-tn) Lik2 # rapporto Lik2/Lik1 # 3486784401