Você está na página 1de 5

Lista de Exercícios 4

Gabriela Araújo

28/05/2022

Inferência

Exercício 1

## Loading required package: xts

## Loading required package: zoo

##
## Attaching package: ’zoo’

## The following objects are masked from ’package:base’:


##
## as.Date, as.Date.numeric

## Loading required package: sp

data("danishuni")

xlog = log(danishuni$Loss)

hist(xlog, prob=TRUE, ylim=c(0, 1), main="Histograma e densidade empírica",


xlab = "Logarítimo das indenizações", ylab = "Densidades",
col = "lightgreen")
lines(density(xlog), lty=5, lwd=2, col="DeepPink1")

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

Logarítimo das indenizações

Exercício 2

## Loading required package: MASS

## Loading required package: survival

for (i in 1:2167) {
ifelse(xlog[i]==0,xlog[i]<-0.0001,xlog[i]<-xlog[i])}

EMVgamma = fitdist(xlog, "gamma", method="mle")


EMVgamma

## Fitting of the distribution ’ gamma ’ by maximum likelihood


## Parameters:
## estimate Std. Error
## shape 1.124754 0.03039553
## rate 1.429267 0.04827005

EMVlnorm = fitdist(xlog, "lnorm", method="mle")


EMVlnorm

## Fitting of the distribution ’ lnorm ’ by maximum likelihood


## Parameters:

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) )

Histograma e densidades empírica, gama e lognormal ajustadas


1.5

Empirica
gamma
Gama
lnorm
Lognormal
1.0
Densidades

0.5
0.0

0 1 2 3 4 5

Logarítimo das indenizações

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")

QQ−plot Indenizações 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

1e−03 1e−01 1e+01 1e−04 1e−02 1e+00

Theoretical quantiles data in log scale

Exercício 5

Quantil observado:

## 95%
## 2.299829

Quantil teórico Gama:

## [1] 2.262092

Quantil teórico LogNormal:

## [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)

## The following object is masked from package:MASS:


##
## housing

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

Você também pode gostar