Escolar Documentos
Profissional Documentos
Cultura Documentos
Lista 04
Lista 04
Gabriela Araújo
28/05/2022
Inferência
Exercício 1
##
## Attaching package: ’zoo’
data("danishuni")
xlog = log(danishuni$Loss)
1
Histograma e densidade empírica
1.0
0.8
Densidades
0.6
0.4
0.2
0.0
0 1 2 3 4 5 6
Exercício 2
for (i in 1:2167) {
ifelse(xlog[i]==0,xlog[i]<-0.0001,xlog[i]<-xlog[i])}
2
## estimate Std. Error
## meanlog -0.7460302 0.02751422
## sdlog 1.2808160 0.01945544
Exercício 3
denscomp(list(EMVgamma,EMVlnorm),
fitcol = c("black", "#4fb6a7"), fitlwd=2, fitlty = c(1,3),
main="Histograma e densidades empírica, gama e lognormal ajustadas",
xlab = "Logarítimo das indenizações", ylab = "Densidades")
lines(density(xlog), lwd=2, lty=5, col = "DeepPink1")
legend( x = "topright",
legend = c("Empirica","Gama","Lognormal"),
col = c("DeepPink1","black","#4fb6a7"), lwd = 2, lty = c(0,0,0),
pch = c(20,20,20) )
Empirica
gamma
Gama
lnorm
Lognormal
1.0
Densidades
0.5
0.0
0 1 2 3 4 5
Exercício 4
Pela análise dos gráficos abaixo, temos que a distribuição ajustada mais adequada para os dados de ind-
enização é a distribuição Gama.
par(mfrow=c(1,2))
qqcomp(list(EMVgamma,EMVlnorm), xlog=TRUE, ylog=TRUE, main="QQ-plot Indenizações",
3
fitcol = c("DeepPink1","lightgreen"),
legendtext=c("Gama","Lognormal"), fitpch=c(4,20))
cdfcomp(list(EMVgamma,EMVlnorm), xlogscale=TRUE, datacol="grey", fitlwd=2,
fitcol = c("DeepPink1","lightgreen"),
legendtext=c("Gama","LogNormal"), xlegend = "topleft",
main="Funções de distribuições ajustadas")
1.0
Gama
1e+00
LogNormal
0.8
Empirical quantiles
0.6
CDF
1e−02
0.4
0.2
Gama
1e−04
Lognormal
0.0
Exercício 5
Quantil observado:
## 95%
## 2.299829
## [1] 2.262092
## [1] 3.899017
A partir da anaálise dos quantis, vê-se que, assim como pela análise dos gráficos de distribuição, a distribuição
Gama tem uma melhor adequação ao conjunto de dados.
4
Apendizagem Estatística
data(credit)
Exercício 7
credit.2<- credit
credit.2$duration = cut(credit.2$duration,c(0,6,12,18,24,36,Inf))
fitbin <- glm(class ~ duration, data=credit.2, family=binomial(link="logit"))
attach(credit.2)
cbind( prop.table(table(duration,class),1),
logit=predict(fitbin,
newdata=data.frame(duration=levels(duration)),
type="response"))
## 0 1 logit
## (0,6] 0.8902439 0.1097561 0.1097561
## (6,12] 0.7581227 0.2418773 0.2418773
## (12,18] 0.7005348 0.2994652 0.2994652
## (18,24] 0.7053571 0.2946429 0.2946429
## (24,36] 0.6013986 0.3986014 0.3986014
## (36,Inf] 0.4827586 0.5172414 0.5172414