Pra ese modelo, usaremos la libreria BPmodel. Se analiza primero el modelo con todas las variables.
datos = read.csv("midata.csv")
completo <- gamlss(Payment/Claims~Kilometres + Zone + Bonus + Make + Insured,data = datos,family = BP(mu.link = "log",sigma.link = "log"),method = CG(),control=gamlss.control(trace = FALSE))
summary(completo)
## Warning in summary.gamlss(completo): summary: vcov has failed, option qr is used instead
## ******************************************************************
## Family: c("BP", "Beta Prime")
##
## Call: gamlss(formula = Payment/Claims ~ Kilometres + Zone + Bonus +
## Make + Insured, family = BP(mu.link = "log", sigma.link = "log"),
## data = datos, method = CG(), control = gamlss.control(trace = FALSE))
##
## Fitting method: CG()
##
## ------------------------------------------------------------------
## Mu link function: log
## Mu Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.692e+00 6.720e-02 129.355 < 2e-16 ***
## Kilometres -4.866e-02 1.207e-02 -4.031 5.80e-05 ***
## Zone -3.754e-02 9.028e-03 -4.158 3.36e-05 ***
## Bonus 7.348e-02 8.300e-03 8.852 < 2e-16 ***
## Make -5.090e-04 6.365e-03 -0.080 0.93626
## Insured 7.732e-06 2.795e-06 2.766 0.00573 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## Sigma link function: log
## Sigma Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.282 2.117 -2.022 0.0433 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## No. of observations in the fit: 1797
## Degrees of Freedom for the fit: 7
## Residual Deg. of Freedom: 1790
## at cycle: 8
##
## Global Deviance: 33992.78
## AIC: 34006.78
## SBC: 34045.24
## ******************************************************************
Se observa que el modelo toma como significativas al 10% todas las variables.
Criterio de Selección
Para aplicar este método se debe crear un modelo vacío del cual iniciará el proceso. Es necesario definir un punto final de búsqueda, ese punto es una formula que en este caso llamaremos horizonte. A continuación el código. Código en R
Se usa la función stepAIC (Extraída de la librería MASS) y se elije trace=TRUE para que SI se muestren los detalles del proceso de selección.
Proceso de selección:
vacio <- gamlss(Payment/Claims~1,data = datos,family = BP(mu.link = "log",sigma.link = "log"),method = CG(),control=gamlss.control(trace = FALSE))
stepe = step(vacio,
scope = list(lower = vacio,upper = completo),
direction = "both")
## Start: AIC=34133.82
## Payment/Claims ~ 1
##
## trying - Kilometres
## trying - Zone
## trying - Bonus
## trying - Make
## trying - Insured
## Df AIC LRT Pr(Chi)
## + Bonus 1 34046 89.812 < 2.2e-16 ***
## + Insured 1 34109 27.062 1.971e-07 ***
## + Kilometres 1 34116 19.405 1.057e-05 ***
## + Zone 1 34121 14.919 0.0001123 ***
## <none> 34134
## + Make 1 34136 0.065 0.7983518
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: AIC=34046
## Payment/Claims ~ Bonus
##
## trying - Bonus
## trying - Kilometres
## trying - Zone
## trying - Make
## trying - Insured
## Df AIC LRT Pr(Chi)
## + Zone 1 34029 18.688 1.539e-05 ***
## + Kilometres 1 34030 17.885 2.347e-05 ***
## + Insured 1 34034 14.078 0.0001754 ***
## <none> 34046
## + Make 1 34048 0.294 0.5877132
## - Bonus 1 34134 89.812 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: AIC=34029.32
## Payment/Claims ~ Bonus + Zone
##
## trying - Bonus
## trying - Zone
## trying - Kilometres
## trying - Make
## trying - Insured
## Df AIC LRT Pr(Chi)
## + Kilometres 1 34012 19.039 1.281e-05 ***
## + Insured 1 34019 12.273 0.0004596 ***
## <none> 34029
## + Make 1 34031 -0.018 1.0000000
## - Zone 1 34046 18.688 1.539e-05 ***
## - Bonus 1 34121 93.581 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: AIC=34012.28
## Payment/Claims ~ Bonus + Zone + Kilometres
##
## trying - Bonus
## trying - Zone
## trying - Kilometres
## trying - Make
## trying - Insured
## Df AIC LRT Pr(Chi)
## + Insured 1 34005 9.493 0.002063 **
## <none> 34012
## + Make 1 34014 0.232 0.629956
## - Kilometres 1 34029 19.039 1.281e-05 ***
## - Zone 1 34030 19.842 8.411e-06 ***
## - Bonus 1 34100 90.125 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: AIC=34004.78
## Payment/Claims ~ Bonus + Zone + Kilometres + Insured
##
## trying - Bonus
## trying - Zone
## trying - Kilometres
## trying - Insured
## trying - Make
## Df AIC LRT Pr(Chi)
## <none> 34005
## + Make 1 34007 0.006 0.940750
## - Insured 1 34012 9.493 0.002063 **
## - Kilometres 1 34019 16.259 5.525e-05 ***
## - Zone 1 34021 18.546 1.659e-05 ***
## - Bonus 1 34082 79.441 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(stepe)
## ******************************************************************
## Family: c("BP", "Beta Prime")
##
## Call: gamlss(formula = Payment/Claims ~ Bonus + Zone + Kilometres +
## Insured, family = BP(mu.link = "log", sigma.link = "log"),
## data = datos, method = CG(), control = gamlss.control(trace = FALSE))
##
## Fitting method: CG()
##
## ------------------------------------------------------------------
## Mu link function: log
## Mu Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.690e+00 6.004e-02 144.731 < 2e-16 ***
## Bonus 7.351e-02 8.293e-03 8.865 < 2e-16 ***
## Zone -3.752e-02 9.020e-03 -4.160 3.33e-05 ***
## Kilometres -4.869e-02 1.206e-02 -4.036 5.67e-05 ***
## Insured 7.694e-06 2.737e-06 2.811 0.00499 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## Sigma link function: log
## Sigma Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.282 2.117 -2.022 0.0433 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## No. of observations in the fit: 1797
## Degrees of Freedom for the fit: 6
## Residual Deg. of Freedom: 1791
## at cycle: 8
##
## Global Deviance: 33992.78
## AIC: 34004.78
## SBC: 34037.75
## ******************************************************************
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.