# Lab. 1 TSdD 2024-2025 (soluzioni) -- 24 settembre 2024 # Esercizio 1 # consultare help(dbinom) per le funzioni R legate alle v.a. Bernoulliana/Binomiale # a) dbinom(3,size=5,prob=0.3) # b) pbinom(3,size=10,prob=0.3) # oppure sum(dbinom(0:3,size=10,prob=0.3)) # c) qbinom(0.95,size=100,prob=0.3) # d) pbinom(5,10,0.2)-pbinom(2,10,0.2) # oppure sum(dbinom(3:5,10,0.2)) # e) rbinom(20,10,0.3) rbinom(20,10,0.7) # Esercizio 2 xx=seq(0,15,1) yy=dpois(xx,3) plot(xx,yy,type="h",lwd=2) # Esercizio 3 # a) curve(dnorm(x,-4,sqrt(1)),from=-10,to=12) curve(dnorm(x,7,sqrt(1)), add=TRUE, lty=2) # b) aa=rnorm(1000,0,1) # qui lo facciamo con 1000 valori hist(aa,prob=T) curve(dnorm(x,0,1), add=TRUE) # density estimation dd=density(aa) lines(dd,lty=3,lwd=2) # Esercizio 4 # consultare help(dgamma) curve(dgamma(x,shape=1,scale=2),from=0, to=10) curve(dgamma(x,shape=2,scale=2),from=0, to=10, add=TRUE,lty=2) curve(dgamma(x,shape=3,scale=2),from=0, to=10, add=TRUE,lty=3) curve(dgamma(x,shape=5,scale=1),from=0, to=10, add=TRUE,lty=4) # Esercizio 5 # consultare help(dexp) curve(dexp(x,rate=1/0.5),from=0, to=5) curve(dexp(x,rate=1),from=0, to=5, add=TRUE,lty=2) curve(dexp(x,rate=1/2),from=0, to=5, add=TRUE,lty=3) # Esercizio 6 # consultare help(dchisq) curve(dchisq(x,df=3),from=0, to=20,ylim=c(0,0.5)) curve(dchisq(x,df=5),lty=2, add=TRUE) curve(dchisq(x,df=10),lty=3, add=TRUE) # Esercizio 7 # consultare help(dnorm) curve(dbeta(x,shape1=0.5,shape2=0.5))