Los datos de conteo al contrario que las variables continuas son números enteros, usualmente representando la frecuencia en la que ocurre un suceso.
No se pueden utilizar los mismos metodos de regrsión lineal po distintas razones:
En R se utiliza \(glm\) especificando \(Family = poisson\) lo cual establece $ errors=poisson$ y \(link=log\).El log link permite que los valores ajustados sean positivos mientras que el erro Poisson tiene en cuenta el hecho de que los datos son enteros y las varianzas son iguales a las medias.
clusters<-read.table('clusters.txt',header=T)
colnames(clusters) <- c('plantas_inf', 'distancia')
names(clusters)
## [1] "plantas_inf" "distancia"
model1<-glm(plantas_inf~distancia,poisson, data = clusters)
summary(model1)
##
## Call:
## glm(formula = plantas_inf ~ distancia, family = poisson, data = clusters)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.5504 -1.3491 -1.1553 0.3877 3.1304
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.186865 0.188728 0.990 0.3221
## distancia -0.006138 0.003667 -1.674 0.0941 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 149.48 on 93 degrees of freedom
## Residual deviance: 146.64 on 92 degrees of freedom
## AIC: 262.41
##
## Number of Fisher Scoring iterations: 5
#los grados de libertad de los residuales no son iguales a la desviación de los residuales, así que se usa quasi-poisson
model2<-glm(plantas_inf~distancia,quasipoisson, data = clusters)
summary(model2)
##
## Call:
## glm(formula = plantas_inf ~ distancia, family = quasipoisson,
## data = clusters)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.5504 -1.3491 -1.1553 0.3877 3.1304
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.186865 0.235364 0.794 0.429
## distancia -0.006138 0.004573 -1.342 0.183
##
## (Dispersion parameter for quasipoisson family taken to be 1.555271)
##
## Null deviance: 149.48 on 93 degrees of freedom
## Residual deviance: 146.64 on 92 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 5
# se observa que esta correción aumenta el p_value a 0.183
xvp <- seq(0,100)
yvp <- predict(model2,list(distancia=xvp))
plot(plantas_inf~distancia,pch=21,col="black",bg="red", data = clusters)
lines(xvp,exp(yvp),col="blue")
# La funcion glm con errores Poisson utiliza el logaritmo del parametro link. asi que los parametros estimados y las predicciones estan en logaritmos
datosp1 <- data.frame(xvp, yvp)
library(ggplot2)
ggplot(data = clusters, aes(x=distancia, y = plantas_inf))+
geom_point(col=rgb(0.8, 0.2, 0.4), size = 3, shape = 19)+
geom_line(data = datosp1, aes(x = xvp, y = yvp))
count<-read.table("cells.txt",header=T)
names(count)
## [1] "cells" "smoker" "age" "sex" "weight"
table(count$cells) # vista general de la distribución de frecuencias
##
## 0 1 2 3 4 5 6 7
## 314 75 50 32 18 13 7 2
tapply(count$cells,count$smoker,mean)
## FALSE TRUE
## 0.5478723 1.9111111
tapply(count$cells,count$weight,mean)
## normal obese over
## 0.5833333 1.2814371 0.9357143
tapply(count$cells,count$sex,mean)
## female male
## 0.6584507 1.2202643
tapply(count$cells,count$age,mean)
## mid old young
## 0.8676471 0.7835821 1.2710280
# parece que los fumadores presentan mayor conteo frente a los que no fuman, los obesos y en sobrepeso frente a los de peso normal, los machos frente a las hembras, y los jovenes frente a los de edad media y los más viejos.
#se debe evaluar la significancia de las diferencias y también si hay interacción entre las variables explicativas.
plantasdf <- as.data.frame(count)
names(plantasdf) <- c('Hojas_dañadas', 'Insecticida', 'Abono', 'Poda', 'Riego')
levels(plantasdf$Insecticida) <- c('Sin', 'Con')
levels(plantasdf$Abono) <- c('Sin', 'Orgánico', 'Inorgánico')
levels(plantasdf$Poda) <- c('Completa', 'Incompleta')
levels(plantasdf$Riego) <- c('Sin', 'Asperción', 'Goteo')
tapply(plantasdf$Hojas_dañadas,plantasdf$Insecticida,mean)
## FALSE TRUE
## 0.5478723 1.9111111
tapply(plantasdf$Hojas_dañadas,plantasdf$Riego,mean)
## normal obese over
## 0.5833333 1.2814371 0.9357143
tapply(plantasdf$Hojas_dañadas,plantasdf$Abono,mean)
## mid old young
## 0.8676471 0.7835821 1.2710280
tapply(plantasdf$Hojas_dañadas,plantasdf$Poda,mean)
## female male
## 0.6584507 1.2202643
model1<-glm(Hojas_dañadas~Insecticida*Abono*Poda*Riego,poisson, data = plantasdf)
summary(model1)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida * Abono * Poda * Riego,
## family = poisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.236 -1.022 -0.851 0.520 3.760
##
## Coefficients: (2 not defined because of singularities)
## Estimate Std. Error z value
## (Intercept) -0.8329 0.3162 -2.634
## InsecticidaTRUE -0.1787 0.5916 -0.302
## Abonoold -0.1830 0.3842 -0.476
## Abonoyoung 0.1398 0.4928 0.284
## Podamale 0.1823 0.4282 0.426
## Riegoobese 1.2384 0.6583 1.881
## Riegoover -0.5534 1.0488 -0.528
## InsecticidaTRUE:Abonoold -1.7227 1.7801 -0.968
## InsecticidaTRUE:Abonoyoung 1.1232 0.7772 1.445
## InsecticidaTRUE:Podamale 0.8293 0.7071 1.173
## Abonoold:Podamale -0.2650 0.6935 -0.382
## Abonoyoung:Podamale -0.2776 0.7254 -0.383
## InsecticidaTRUE:Riegoobese 3.5689 1.3990 2.551
## InsecticidaTRUE:Riegoover 2.2581 1.3601 1.660
## Abonoold:Riegoobese -0.9280 0.7113 -1.305
## Abonoyoung:Riegoobese -1.2384 1.2555 -0.986
## Abonoold:Riegoover 1.0013 1.0849 0.923
## Abonoyoung:Riegoover 0.5534 1.3202 0.419
## Podamale:Riegoobese -1.1583 0.7704 -1.503
## Podamale:Riegoover 0.7985 1.1202 0.713
## InsecticidaTRUE:Abonoold:Podamale 1.8342 1.6027 1.144
## InsecticidaTRUE:Abonoyoung:Podamale -0.8249 0.9955 -0.829
## InsecticidaTRUE:Abonoold:Riegoobese 0.8298 2.4428 0.340
## InsecticidaTRUE:Abonoyoung:Riegoobese -2.2108 0.7978 -2.771
## InsecticidaTRUE:Abonoold:Riegoover 1.1275 1.2407 0.909
## InsecticidaTRUE:Abonoyoung:Riegoover -1.6156 1.6277 -0.993
## InsecticidaTRUE:Podamale:Riegoobese -2.2379 1.3061 -1.713
## InsecticidaTRUE:Podamale:Riegoover -2.5033 1.5507 -1.614
## Abonoold:Podamale:Riegoobese 2.2210 0.9779 2.271
## Abonoyoung:Podamale:Riegoobese 2.5346 1.4309 1.771
## Abonoold:Podamale:Riegoover -1.0641 1.4428 -0.738
## Abonoyoung:Podamale:Riegoover -1.1087 1.5592 -0.711
## InsecticidaTRUE:Abonoold:Podamale:Riegoobese -1.6169 2.2440 -0.721
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoobese NA NA NA
## InsecticidaTRUE:Abonoold:Podamale:Riegoover NA NA NA
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoover 2.4160 1.9712 1.226
## Pr(>|z|)
## (Intercept) 0.00844 **
## InsecticidaTRUE 0.76262
## Abonoold 0.63384
## Abonoyoung 0.77671
## Podamale 0.67025
## Riegoobese 0.05994 .
## Riegoover 0.59775
## InsecticidaTRUE:Abonoold 0.33317
## InsecticidaTRUE:Abonoyoung 0.14840
## InsecticidaTRUE:Podamale 0.24088
## Abonoold:Podamale 0.70236
## Abonoyoung:Podamale 0.70192
## InsecticidaTRUE:Riegoobese 0.01074 *
## InsecticidaTRUE:Riegoover 0.09687 .
## Abonoold:Riegoobese 0.19200
## Abonoyoung:Riegoobese 0.32394
## Abonoold:Riegoover 0.35603
## Abonoyoung:Riegoover 0.67509
## Podamale:Riegoobese 0.13272
## Podamale:Riegoover 0.47594
## InsecticidaTRUE:Abonoold:Podamale 0.25243
## InsecticidaTRUE:Abonoyoung:Podamale 0.40729
## InsecticidaTRUE:Abonoold:Riegoobese 0.73408
## InsecticidaTRUE:Abonoyoung:Riegoobese 0.00559 **
## InsecticidaTRUE:Abonoold:Riegoover 0.36346
## InsecticidaTRUE:Abonoyoung:Riegoover 0.32091
## InsecticidaTRUE:Podamale:Riegoobese 0.08662 .
## InsecticidaTRUE:Podamale:Riegoover 0.10647
## Abonoold:Podamale:Riegoobese 0.02313 *
## Abonoyoung:Podamale:Riegoobese 0.07651 .
## Abonoold:Podamale:Riegoover 0.46081
## Abonoyoung:Podamale:Riegoover 0.47704
## InsecticidaTRUE:Abonoold:Podamale:Riegoobese 0.47119
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoobese NA
## InsecticidaTRUE:Abonoold:Podamale:Riegoover NA
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoover 0.22033
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 736.33 on 477 degrees of freedom
## AIC: 1318
##
## Number of Fisher Scoring iterations: 6
#El modelo muestra sobredispersión. La desvición residual (736.33) es mayor que los grados de libertad residuales (477). Por tanto se debe utilizar el modo quasipoisson
model2<-glm(Hojas_dañadas~Insecticida*Abono*Poda*Riego,quasipoisson, data = plantasdf)
summary(model2)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida * Abono * Poda * Riego,
## family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.236 -1.022 -0.851 0.520 3.760
##
## Coefficients: (2 not defined because of singularities)
## Estimate Std. Error t value
## (Intercept) -0.8329 0.4307 -1.934
## InsecticidaTRUE -0.1787 0.8057 -0.222
## Abonoold -0.1830 0.5233 -0.350
## Abonoyoung 0.1398 0.6712 0.208
## Podamale 0.1823 0.5831 0.313
## Riegoobese 1.2384 0.8965 1.381
## Riegoover -0.5534 1.4284 -0.387
## InsecticidaTRUE:Abonoold -1.7227 2.4243 -0.711
## InsecticidaTRUE:Abonoyoung 1.1232 1.0584 1.061
## InsecticidaTRUE:Podamale 0.8293 0.9630 0.861
## Abonoold:Podamale -0.2650 0.9445 -0.281
## Abonoyoung:Podamale -0.2776 0.9879 -0.281
## InsecticidaTRUE:Riegoobese 3.5689 1.9053 1.873
## InsecticidaTRUE:Riegoover 2.2581 1.8524 1.219
## Abonoold:Riegoobese -0.9280 0.9687 -0.958
## Abonoyoung:Riegoobese -1.2384 1.7098 -0.724
## Abonoold:Riegoover 1.0013 1.4776 0.678
## Abonoyoung:Riegoover 0.5534 1.7980 0.308
## Podamale:Riegoobese -1.1583 1.0493 -1.104
## Podamale:Riegoover 0.7985 1.5256 0.523
## InsecticidaTRUE:Abonoold:Podamale 1.8342 2.1827 0.840
## InsecticidaTRUE:Abonoyoung:Podamale -0.8249 1.3558 -0.608
## InsecticidaTRUE:Abonoold:Riegoobese 0.8298 3.3269 0.249
## InsecticidaTRUE:Abonoyoung:Riegoobese -2.2108 1.0865 -2.035
## InsecticidaTRUE:Abonoold:Riegoover 1.1275 1.6897 0.667
## InsecticidaTRUE:Abonoyoung:Riegoover -1.6156 2.2168 -0.729
## InsecticidaTRUE:Podamale:Riegoobese -2.2379 1.7788 -1.258
## InsecticidaTRUE:Podamale:Riegoover -2.5033 2.1120 -1.185
## Abonoold:Podamale:Riegoobese 2.2210 1.3318 1.668
## Abonoyoung:Podamale:Riegoobese 2.5346 1.9488 1.301
## Abonoold:Podamale:Riegoover -1.0641 1.9650 -0.542
## Abonoyoung:Podamale:Riegoover -1.1087 2.1234 -0.522
## InsecticidaTRUE:Abonoold:Podamale:Riegoobese -1.6169 3.0561 -0.529
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoobese NA NA NA
## InsecticidaTRUE:Abonoold:Podamale:Riegoover NA NA NA
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoover 2.4160 2.6846 0.900
## Pr(>|t|)
## (Intercept) 0.0537 .
## InsecticidaTRUE 0.8246
## Abonoold 0.7267
## Abonoyoung 0.8351
## Podamale 0.7547
## Riegoobese 0.1678
## Riegoover 0.6986
## InsecticidaTRUE:Abonoold 0.4777
## InsecticidaTRUE:Abonoyoung 0.2892
## InsecticidaTRUE:Podamale 0.3896
## Abonoold:Podamale 0.7791
## Abonoyoung:Podamale 0.7788
## InsecticidaTRUE:Riegoobese 0.0617 .
## InsecticidaTRUE:Riegoover 0.2234
## Abonoold:Riegoobese 0.3386
## Abonoyoung:Riegoobese 0.4693
## Abonoold:Riegoover 0.4983
## Abonoyoung:Riegoover 0.7584
## Podamale:Riegoobese 0.2702
## Podamale:Riegoover 0.6009
## InsecticidaTRUE:Abonoold:Podamale 0.4011
## InsecticidaTRUE:Abonoyoung:Podamale 0.5432
## InsecticidaTRUE:Abonoold:Riegoobese 0.8031
## InsecticidaTRUE:Abonoyoung:Riegoobese 0.0424 *
## InsecticidaTRUE:Abonoold:Riegoover 0.5049
## InsecticidaTRUE:Abonoyoung:Riegoover 0.4665
## InsecticidaTRUE:Podamale:Riegoobese 0.2090
## InsecticidaTRUE:Podamale:Riegoover 0.2365
## Abonoold:Podamale:Riegoobese 0.0960 .
## Abonoyoung:Podamale:Riegoobese 0.1940
## Abonoold:Podamale:Riegoover 0.5884
## Abonoyoung:Podamale:Riegoover 0.6018
## InsecticidaTRUE:Abonoold:Podamale:Riegoobese 0.5970
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoobese NA
## InsecticidaTRUE:Abonoold:Podamale:Riegoover NA
## InsecticidaTRUE:Abonoyoung:Podamale:Riegoover 0.3686
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.854815)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 736.33 on 477 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model3<-update(model2, ~. -Insecticida:Abono:Poda:Riego)
summary(model3)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego + Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego + Abono:Poda:Riego, family = quasipoisson,
## data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2442 -1.0477 -0.8921 0.5195 3.7613
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.897195 0.436988 -2.053 0.04060 *
## InsecticidaTRUE 0.030263 0.735386 0.041 0.96719
## Abonoold -0.118726 0.528165 -0.225 0.82224
## Abonoyoung 0.289259 0.639618 0.452 0.65130
## Podamale 0.297192 0.570009 0.521 0.60234
## Riegoobese 1.302660 0.898307 1.450 0.14768
## Riegoover -0.005052 1.027198 -0.005 0.99608
## InsecticidaTRUE:Abonoold -0.566584 1.700590 -0.333 0.73915
## InsecticidaTRUE:Abonoyoung 0.757297 0.939746 0.806 0.42073
## InsecticidaTRUE:Podamale 0.527345 0.867294 0.608 0.54345
## Abonoold:Podamale -0.379884 0.935365 -0.406 0.68483
## Abonoyoung:Podamale -0.610703 0.920969 -0.663 0.50758
## InsecticidaTRUE:Riegoobese 3.924591 1.475476 2.660 0.00808 **
## InsecticidaTRUE:Riegoover 1.192159 1.259888 0.946 0.34450
## Abonoold:Riegoobese -0.993355 0.970484 -1.024 0.30656
## Abonoyoung:Riegoobese -1.346913 1.459454 -0.923 0.35653
## Abonoold:Riegoover 0.454217 1.090260 0.417 0.67715
## Abonoyoung:Riegoover -0.483955 1.300866 -0.372 0.71004
## Podamale:Riegoobese -1.273202 1.040701 -1.223 0.22178
## Podamale:Riegoover 0.154097 1.098781 0.140 0.88853
## InsecticidaTRUE:Abonoold:Podamale 0.771116 1.451512 0.531 0.59549
## InsecticidaTRUE:Abonoyoung:Podamale -0.210317 1.140384 -0.184 0.85376
## InsecticidaTRUE:Abonoold:Riegoobese -0.882951 1.187871 -0.743 0.45766
## InsecticidaTRUE:Abonoyoung:Riegoobese -2.453315 1.047067 -2.343 0.01954 *
## InsecticidaTRUE:Abonoold:Riegoover 0.823018 1.528233 0.539 0.59045
## InsecticidaTRUE:Abonoyoung:Riegoover 0.040795 1.223664 0.033 0.97342
## InsecticidaTRUE:Podamale:Riegoobese -2.500668 1.369941 -1.825 0.06857 .
## InsecticidaTRUE:Podamale:Riegoover -1.110222 1.217531 -0.912 0.36230
## Abonoold:Podamale:Riegoobese 2.338617 1.324805 1.765 0.07816 .
## Abonoyoung:Podamale:Riegoobese 2.822032 1.623849 1.738 0.08288 .
## Abonoold:Podamale:Riegoover -0.442066 1.545451 -0.286 0.77497
## Abonoyoung:Podamale:Riegoover 0.357807 1.291194 0.277 0.78181
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.847991)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 737.87 on 479 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
anova(model2, model3, test = 'Chisq')
## Analysis of Deviance Table
##
## Model 1: Hojas_dañadas ~ Insecticida * Abono * Poda * Riego
## Model 2: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego + Abono:Poda:Riego
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 477 736.33
## 2 479 737.87 -2 -1.5383 0.6606
##################### REDUCCIÓN DEL MODELO
model4 <- update(model3, ~. -Abono:Poda:Riego)
summary(model4)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego + Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2761 -1.0485 -0.8915 0.5443 3.7086
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.74288 0.38852 -1.912 0.05646 .
## InsecticidaTRUE -0.08844 0.69841 -0.127 0.89929
## Abonoold -0.30828 0.47215 -0.653 0.51411
## Abonoyoung 0.01856 0.60126 0.031 0.97539
## Podamale 0.01054 0.51495 0.020 0.98368
## Riegoobese -0.41583 0.72917 -0.570 0.56875
## Riegoover 0.24455 0.70327 0.348 0.72819
## InsecticidaTRUE:Abonoold 0.18576 1.14901 0.162 0.87163
## InsecticidaTRUE:Abonoyoung 0.97218 0.92185 1.055 0.29214
## InsecticidaTRUE:Podamale 0.76666 0.83280 0.921 0.35773
## Abonoold:Podamale 0.10904 0.65881 0.166 0.86861
## Abonoyoung:Podamale -0.03260 0.76096 -0.043 0.96585
## InsecticidaTRUE:Riegoobese 2.80870 1.04112 2.698 0.00723 **
## InsecticidaTRUE:Riegoover 0.77721 1.09880 0.707 0.47971
## Abonoold:Riegoobese 0.80417 0.71163 1.130 0.25902
## Abonoyoung:Riegoobese 0.93274 0.80803 1.154 0.24893
## Abonoold:Riegoover 0.20817 0.73675 0.283 0.77764
## Abonoyoung:Riegoover -0.44310 0.88662 -0.500 0.61747
## Podamale:Riegoobese 0.74524 0.60716 1.227 0.22026
## Podamale:Riegoover -0.02543 0.68713 -0.037 0.97049
## InsecticidaTRUE:Abonoold:Podamale -0.26887 1.10251 -0.244 0.80743
## InsecticidaTRUE:Abonoyoung:Podamale -0.71483 1.08280 -0.660 0.50946
## InsecticidaTRUE:Abonoold:Riegoobese -0.36786 1.04834 -0.351 0.72582
## InsecticidaTRUE:Abonoyoung:Riegoobese -1.91107 0.97067 -1.969 0.04954 *
## InsecticidaTRUE:Abonoold:Riegoover 0.58648 1.20671 0.486 0.62718
## InsecticidaTRUE:Abonoyoung:Riegoover 0.21372 1.19097 0.179 0.85766
## InsecticidaTRUE:Podamale:Riegoobese -1.67300 0.88376 -1.893 0.05895 .
## InsecticidaTRUE:Podamale:Riegoover -0.70839 0.95015 -0.746 0.45630
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.847062)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 745.31 on 483 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
anova(model3, model4, test = 'Chisq')
## Analysis of Deviance Table
##
## Model 1: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego + Abono:Poda:Riego
## Model 2: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 479 737.87
## 2 483 745.31 -4 -7.4416 0.4024
model5 <- update(model4, ~. -Poda:Riego)
summary(model5)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2761 -1.0485 -0.8915 0.5443 3.7086
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.74288 0.38852 -1.912 0.05646 .
## InsecticidaTRUE -0.08844 0.69841 -0.127 0.89929
## Abonoold -0.30828 0.47215 -0.653 0.51411
## Abonoyoung 0.01856 0.60126 0.031 0.97539
## Podamale 0.01054 0.51495 0.020 0.98368
## Riegoobese -0.41583 0.72917 -0.570 0.56875
## Riegoover 0.24455 0.70327 0.348 0.72819
## InsecticidaTRUE:Abonoold 0.18576 1.14901 0.162 0.87163
## InsecticidaTRUE:Abonoyoung 0.97218 0.92185 1.055 0.29214
## InsecticidaTRUE:Podamale 0.76666 0.83280 0.921 0.35773
## Abonoold:Podamale 0.10904 0.65881 0.166 0.86861
## Abonoyoung:Podamale -0.03260 0.76096 -0.043 0.96585
## InsecticidaTRUE:Riegoobese 2.80870 1.04112 2.698 0.00723 **
## InsecticidaTRUE:Riegoover 0.77721 1.09880 0.707 0.47971
## Abonoold:Riegoobese 0.80417 0.71163 1.130 0.25902
## Abonoyoung:Riegoobese 0.93274 0.80803 1.154 0.24893
## Abonoold:Riegoover 0.20817 0.73675 0.283 0.77764
## Abonoyoung:Riegoover -0.44310 0.88662 -0.500 0.61747
## InsecticidaTRUE:Abonoold:Podamale -0.26887 1.10251 -0.244 0.80743
## InsecticidaTRUE:Abonoyoung:Podamale -0.71483 1.08280 -0.660 0.50946
## InsecticidaTRUE:Abonoold:Riegoobese -0.36786 1.04834 -0.351 0.72582
## InsecticidaTRUE:Abonoyoung:Riegoobese -1.91107 0.97067 -1.969 0.04954 *
## InsecticidaTRUE:Abonoold:Riegoover 0.58648 1.20671 0.486 0.62718
## InsecticidaTRUE:Abonoyoung:Riegoover 0.21372 1.19097 0.179 0.85766
## InsecticidaFALSE:Podamale:Riegoobese 0.74524 0.60716 1.227 0.22026
## InsecticidaTRUE:Podamale:Riegoobese -0.92776 0.64217 -1.445 0.14919
## InsecticidaFALSE:Podamale:Riegoover -0.02543 0.68713 -0.037 0.97049
## InsecticidaTRUE:Podamale:Riegoover -0.73383 0.65623 -1.118 0.26402
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.847062)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 745.31 on 483 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
anova(model4, model5, test = 'Chisq')
## Analysis of Deviance Table
##
## Model 1: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Poda:Riego + Insecticida:Abono:Poda + Insecticida:Abono:Riego +
## Insecticida:Poda:Riego
## Model 2: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Insecticida:Abono:Poda + Insecticida:Abono:Riego + Insecticida:Poda:Riego
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 483 745.31
## 2 483 745.31 0 0
model6 <- update(model5, ~. -Insecticida:Abono:Riego)
summary(model6)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego + Insecticida:Abono:Poda + Insecticida:Poda:Riego,
## family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2453 -1.0503 -0.8907 0.5662 3.6893
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.75285 0.38163 -1.973 0.0491 *
## InsecticidaTRUE -0.11677 0.68440 -0.171 0.8646
## Abonoold -0.33768 0.45664 -0.739 0.4600
## Abonoyoung 0.15191 0.57319 0.265 0.7911
## Podamale -0.17186 0.51591 -0.333 0.7392
## Riegoobese -0.03207 0.54936 -0.058 0.9535
## Riegoover 0.17932 0.57601 0.311 0.7557
## InsecticidaTRUE:Abonoold 0.61688 0.91821 0.672 0.5020
## InsecticidaTRUE:Abonoyoung 0.89880 0.86815 1.035 0.3010
## InsecticidaTRUE:Podamale 1.13273 0.80791 1.402 0.1615
## Abonoold:Podamale 0.25484 0.60159 0.424 0.6720
## Abonoyoung:Podamale 0.38924 0.71360 0.545 0.5857
## InsecticidaTRUE:Riegoobese 1.92469 0.75561 2.547 0.0112 *
## InsecticidaTRUE:Riegoover 1.01942 0.72655 1.403 0.1612
## Abonoold:Riegoobese 0.47568 0.49201 0.967 0.3341
## Abonoyoung:Riegoobese -0.45879 0.44731 -1.026 0.3056
## Abonoold:Riegoover 0.31619 0.55787 0.567 0.5711
## Abonoyoung:Riegoover -0.46232 0.54319 -0.851 0.3951
## InsecticidaTRUE:Abonoold:Podamale -0.75829 1.00466 -0.755 0.4508
## InsecticidaTRUE:Abonoyoung:Podamale -1.47055 1.00153 -1.468 0.1427
## InsecticidaFALSE:Podamale:Riegoobese 0.77141 0.56792 1.358 0.1750
## InsecticidaTRUE:Podamale:Riegoobese -0.67611 0.62256 -1.086 0.2780
## InsecticidaFALSE:Podamale:Riegoover 0.07750 0.62352 0.124 0.9011
## InsecticidaTRUE:Podamale:Riegoover -0.66807 0.63497 -1.052 0.2933
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.853243)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 754.97 on 487 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
anova(model5, model6, test = 'Chisq')
## Analysis of Deviance Table
##
## Model 1: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Insecticida:Abono:Poda + Insecticida:Abono:Riego + Insecticida:Poda:Riego
## Model 2: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Insecticida:Abono:Poda + Insecticida:Poda:Riego
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 483 745.31
## 2 487 754.97 -4 -9.6651 0.2642
model7 <- update(model6, ~. -Insecticida:Poda:Riego)
summary(model7)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego + Insecticida:Abono:Poda, family = quasipoisson,
## data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2952 -1.0887 -0.9559 0.5270 3.7538
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.79796 0.37862 -2.108 0.0356 *
## InsecticidaTRUE 0.04548 0.67508 0.067 0.9463
## Abonoold -0.41677 0.46063 -0.905 0.3660
## Abonoyoung 0.10830 0.58078 0.186 0.8522
## Podamale 0.01454 0.45853 0.032 0.9747
## Riegoobese 0.46372 0.38472 1.205 0.2287
## Riegoover 0.20581 0.42521 0.484 0.6286
## InsecticidaTRUE:Abonoold 1.27909 0.81620 1.567 0.1177
## InsecticidaTRUE:Abonoyoung 1.18092 0.83527 1.414 0.1580
## InsecticidaTRUE:Podamale 0.73485 0.75883 0.968 0.3333
## Abonoold:Podamale 0.56854 0.54055 1.052 0.2934
## Abonoyoung:Podamale 0.29454 0.71186 0.414 0.6792
## InsecticidaTRUE:Riegoobese 0.89679 0.38736 2.315 0.0210 *
## InsecticidaTRUE:Riegoover 0.34435 0.41008 0.840 0.4015
## Abonoold:Riegoobese 0.22783 0.44304 0.514 0.6073
## Abonoyoung:Riegoobese -0.40560 0.43462 -0.933 0.3512
## Abonoold:Riegoover 0.30851 0.50432 0.612 0.5410
## Abonoyoung:Riegoover -0.25429 0.52206 -0.487 0.6264
## InsecticidaTRUE:Abonoold:Podamale -1.51650 0.89946 -1.686 0.0924 .
## InsecticidaTRUE:Abonoyoung:Podamale -1.64883 0.97289 -1.695 0.0908 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.884339)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 762.42 on 491 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
anova(model6, model7, test = 'Chisq')
## Analysis of Deviance Table
##
## Model 1: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Insecticida:Abono:Poda + Insecticida:Poda:Riego
## Model 2: Hojas_dañadas ~ Insecticida + Abono + Poda + Riego + Insecticida:Abono +
## Insecticida:Poda + Abono:Poda + Insecticida:Riego + Abono:Riego +
## Insecticida:Abono:Poda
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 487 754.97
## 2 491 762.42 -4 -7.4478 0.4035
model8 <- update(model7, ~. -Insecticida:Abono:Poda)
summary(model8)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Abono:Poda + Insecticida:Riego +
## Abono:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.2485 -1.0962 -0.8391 0.4754 3.7227
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.163438 0.386474 -3.010 0.00274 **
## InsecticidaTRUE 0.959414 0.419901 2.285 0.02275 *
## Abonoold -0.006221 0.451939 -0.014 0.98902
## Abonoyoung 0.693808 0.473827 1.464 0.14376
## Podamale 0.527894 0.413985 1.275 0.20286
## Riegoobese 0.430265 0.382651 1.124 0.26138
## Riegoover 0.119326 0.423360 0.282 0.77817
## InsecticidaTRUE:Abonoold 0.052679 0.384881 0.137 0.89119
## InsecticidaTRUE:Abonoyoung -0.051240 0.417601 -0.123 0.90239
## InsecticidaTRUE:Podamale -0.493250 0.343067 -1.438 0.15113
## Abonoold:Podamale -0.041974 0.450676 -0.093 0.92583
## Abonoyoung:Podamale -0.536992 0.464819 -1.155 0.24854
## InsecticidaTRUE:Riegoobese 1.055727 0.381725 2.766 0.00589 **
## InsecticidaTRUE:Riegoover 0.473977 0.403065 1.176 0.24019
## Abonoold:Riegoobese 0.230033 0.445155 0.517 0.60556
## Abonoyoung:Riegoobese -0.494798 0.441885 -1.120 0.26337
## Abonoold:Riegoover 0.375820 0.503663 0.746 0.45592
## Abonoyoung:Riegoover -0.212990 0.517704 -0.411 0.68095
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.881849)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 769.34 on 493 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model9 <- update(model8, ~. -Abono:Poda)
summary(model9)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Insecticida:Riego +
## Abono:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.3488 -1.1072 -0.8810 0.5173 3.7211
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.08811 0.31758 -3.426 0.000663 ***
## InsecticidaTRUE 1.05173 0.40423 2.602 0.009551 **
## Abonoold -0.04163 0.37873 -0.110 0.912510
## Abonoyoung 0.38985 0.38768 1.006 0.315101
## Podamale 0.40165 0.23460 1.712 0.087513 .
## Riegoobese 0.48742 0.36489 1.336 0.182226
## Riegoover 0.14153 0.41569 0.340 0.733649
## InsecticidaTRUE:Abonoold 0.09813 0.37662 0.261 0.794541
## InsecticidaTRUE:Abonoyoung -0.06399 0.41072 -0.156 0.876254
## InsecticidaTRUE:Podamale -0.66923 0.31348 -2.135 0.033264 *
## InsecticidaTRUE:Riegoobese 1.12634 0.38057 2.960 0.003228 **
## InsecticidaTRUE:Riegoover 0.53806 0.40001 1.345 0.179202
## Abonoold:Riegoobese 0.15286 0.42995 0.356 0.722351
## Abonoyoung:Riegoobese -0.65045 0.41398 -1.571 0.116771
## Abonoold:Riegoover 0.31497 0.49904 0.631 0.528227
## Abonoyoung:Riegoover -0.24118 0.50832 -0.474 0.635373
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.868169)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 773.37 on 495 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model10 <- update(model9, ~. -Abono:Riego)
summary(model10)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Poda + Insecticida:Riego,
## family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.4881 -1.1004 -0.8670 0.4775 3.7942
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.0925 0.2871 -3.806 0.000159 ***
## InsecticidaTRUE 1.2054 0.3849 3.132 0.001839 **
## Abonoold 0.1040 0.2673 0.389 0.697254
## Abonoyoung 0.1852 0.3250 0.570 0.569027
## Podamale 0.3696 0.2323 1.591 0.112317
## Riegoobese 0.4866 0.2371 2.052 0.040656 *
## Riegoover 0.2543 0.2559 0.994 0.320849
## InsecticidaTRUE:Abonoold 0.1627 0.3604 0.451 0.651953
## InsecticidaTRUE:Abonoyoung -0.2361 0.3913 -0.603 0.546594
## InsecticidaTRUE:Podamale -0.6164 0.3094 -1.992 0.046871 *
## InsecticidaTRUE:Riegoobese 0.8280 0.3242 2.554 0.010939 *
## InsecticidaTRUE:Riegoover 0.3707 0.3606 1.028 0.304413
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.862022)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 780.58 on 499 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model11 <- update(model10, ~. -Insecticida:Poda)
summary(model11)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Poda + Riego +
## Insecticida:Abono + Insecticida:Riego, family = quasipoisson,
## data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.5581 -1.1478 -0.9219 0.4473 3.7296
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.85571 0.25350 -3.376 0.000794 ***
## InsecticidaTRUE 0.76979 0.31533 2.441 0.014984 *
## Abonoold -0.10802 0.24735 -0.437 0.662517
## Abonoyoung 0.14119 0.32440 0.435 0.663593
## Podamale 0.02563 0.16060 0.160 0.873254
## Riegoobese 0.54619 0.23702 2.304 0.021611 *
## Riegoover 0.28345 0.25651 1.105 0.269678
## InsecticidaTRUE:Abonoold 0.35015 0.34939 1.002 0.316733
## InsecticidaTRUE:Abonoyoung -0.16611 0.38925 -0.427 0.669750
## InsecticidaTRUE:Riegoobese 0.72440 0.32020 2.262 0.024105 *
## InsecticidaTRUE:Riegoover 0.37623 0.36108 1.042 0.297943
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.861229)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 787.77 on 500 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model12 <- update(model11, ~. -Poda)
summary(model12)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Abono + Riego + Insecticida:Abono +
## Insecticida:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.5520 -1.1510 -0.9296 0.4385 3.7254
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8391 0.2306 -3.639 0.000302 ***
## InsecticidaTRUE 0.7724 0.3145 2.456 0.014385 *
## Abonoold -0.1238 0.2267 -0.546 0.585178
## Abonoyoung 0.1376 0.3234 0.425 0.670685
## Riegoobese 0.5509 0.2351 2.343 0.019523 *
## Riegoover 0.2861 0.2559 1.118 0.264072
## InsecticidaTRUE:Abonoold 0.3682 0.3304 1.115 0.265564
## InsecticidaTRUE:Abonoyoung -0.1648 0.3890 -0.424 0.671960
## InsecticidaTRUE:Riegoobese 0.7235 0.3201 2.260 0.024233 *
## InsecticidaTRUE:Riegoover 0.3703 0.3591 1.031 0.302893
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.85918)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 787.82 on 501 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model13 <- update(model12, ~. -Abono)
summary(model13)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Riego + Insecticida:Abono +
## Insecticida:Riego, family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.5520 -1.1510 -0.9296 0.4385 3.7254
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8391 0.2306 -3.639 0.000302 ***
## InsecticidaTRUE 0.7724 0.3145 2.456 0.014385 *
## Riegoobese 0.5509 0.2351 2.343 0.019523 *
## Riegoover 0.2861 0.2559 1.118 0.264072
## InsecticidaFALSE:Abonoold -0.1238 0.2267 -0.546 0.585178
## InsecticidaTRUE:Abonoold 0.2444 0.2404 1.017 0.309685
## InsecticidaFALSE:Abonoyoung 0.1376 0.3235 0.425 0.670685
## InsecticidaTRUE:Abonoyoung -0.0272 0.2161 -0.126 0.899876
## InsecticidaTRUE:Riegoobese 0.7235 0.3201 2.260 0.024233 *
## InsecticidaTRUE:Riegoover 0.3703 0.3591 1.031 0.302893
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.85918)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 787.82 on 501 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model14 <- update(model13, ~. -Insecticida:Abono)
summary(model14)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Riego + Insecticida:Riego,
## family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.6511 -1.1742 -0.9148 0.5533 3.6436
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8712 0.1760 -4.950 1.01e-06 ***
## InsecticidaTRUE 0.8224 0.2479 3.318 0.000973 ***
## Riegoobese 0.4993 0.2260 2.209 0.027598 *
## Riegoover 0.2618 0.2522 1.038 0.299723
## InsecticidaTRUE:Riegoobese 0.8063 0.3105 2.597 0.009675 **
## InsecticidaTRUE:Riegoover 0.4935 0.3442 1.434 0.152226
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.827927)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 792.85 on 505 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
model15 <- update(model14, ~. -Riego[c(1,3),])
summary(model15)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida + Riego + Insecticida:Riego,
## family = quasipoisson, data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.6511 -1.1742 -0.9148 0.5533 3.6436
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8712 0.1760 -4.950 1.01e-06 ***
## InsecticidaTRUE 0.8224 0.2479 3.318 0.000973 ***
## Riegoobese 0.4993 0.2260 2.209 0.027598 *
## Riegoover 0.2618 0.2522 1.038 0.299723
## InsecticidaTRUE:Riegoobese 0.8063 0.3105 2.597 0.009675 **
## InsecticidaTRUE:Riegoover 0.4935 0.3442 1.434 0.152226
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 1.827927)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 792.85 on 505 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
count$weight
## [1] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [9] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [17] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "over"
## [25] "over" "over" "over" "over" "over" "obese" "obese" "obese"
## [33] "obese" "obese" "normal" "normal" "normal" "normal" "normal" "over"
## [41] "over" "over" "over" "obese" "obese" "obese" "obese" "obese"
## [49] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [57] "obese" "obese" "obese" "obese" "obese" "normal" "normal" "normal"
## [65] "normal" "normal" "normal" "normal" "over" "over" "over" "normal"
## [73] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "over"
## [81] "over" "over" "over" "over" "obese" "obese" "obese" "normal"
## [89] "normal" "normal" "normal" "normal" "normal" "normal" "over" "over"
## [97] "over" "over" "over" "over" "over" "over" "obese" "obese"
## [105] "over" "over" "over" "over" "over" "over" "over" "over"
## [113] "over" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [121] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [129] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [137] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [145] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "normal"
## [153] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [161] "over" "over" "normal" "normal" "normal" "normal" "normal" "normal"
## [169] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [177] "normal" "over" "over" "over" "over" "over" "over" "over"
## [185] "over" "over" "over" "over" "over" "over" "over" "over"
## [193] "over" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [201] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [209] "obese" "obese" "obese" "obese" "obese" "normal" "normal" "normal"
## [217] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [225] "normal" "over" "over" "normal" "normal" "normal" "normal" "normal"
## [233] "normal" "normal" "over" "over" "over" "over" "over" "over"
## [241] "over" "over" "over" "obese" "obese" "obese" "normal" "normal"
## [249] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [257] "normal" "over" "over" "over" "over" "over" "obese" "normal"
## [265] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [273] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [281] "over" "obese" "obese" "normal" "normal" "normal" "normal" "normal"
## [289] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [297] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [305] "normal" "normal" "over" "over" "over" "over" "obese" "obese"
## [313] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [321] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [329] "over" "over" "over" "over" "over" "over" "over" "over"
## [337] "over" "over" "over" "over" "over" "over" "over" "over"
## [345] "over" "over" "obese" "obese" "obese" "obese" "obese" "obese"
## [353] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [361] "obese" "obese" "obese" "normal" "normal" "normal" "normal" "normal"
## [369] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [377] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [385] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [393] "normal" "over" "over" "over" "over" "over" "over" "over"
## [401] "over" "over" "over" "over" "over" "over" "over" "over"
## [409] "over" "over" "over" "over" "over" "over" "over" "over"
## [417] "over" "over" "over" "over" "over" "over" "over" "over"
## [425] "over" "over" "over" "over" "over" "over" "over" "over"
## [433] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [441] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [449] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [457] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [465] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [473] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [481] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [489] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [497] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [505] "normal" "normal" "normal" "normal" "normal" "normal" "normal"
########################
we <- factor(plantasdf$Riego,
levels = c('normal','obese','over'))
class(plantasdf$Riego)
## [1] "character"
class(we)
## [1] "factor"
newWt<-we
levels(newWt)[c(1,3)]<-""
levels(newWt)
## [1] "" "obese"
newwe <- we=='obese'
#nowe<- we==c('normal', 'over')
#finalwe<-
newwe
## [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
## [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE
## [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
## [61] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [85] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [97] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE
## [109] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [121] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [133] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [145] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
## [157] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [169] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [181] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [193] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [205] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE
## [217] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [229] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [241] FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [253] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
## [265] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [277] FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
## [289] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [301] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
## [313] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [325] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [337] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
## [349] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [361] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [373] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [385] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [397] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [409] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [421] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [433] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [445] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [457] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [469] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [481] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [493] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [505] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
model16<-glm(Hojas_dañadas~Insecticida*newwe,poisson, data = plantasdf)
summary(model16)
##
## Call:
## glm(formula = Hojas_dañadas ~ Insecticida * newwe, family = poisson,
## data = plantasdf)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.6511 -1.1742 -0.9709 0.5217 3.8157
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.75224 0.09325 -8.067 7.21e-16 ***
## InsecticidaTRUE 1.05234 0.12690 8.293 < 2e-16 ***
## newweTRUE 0.38029 0.14030 2.711 0.00672 **
## InsecticidaTRUE:newweTRUE 0.57644 0.18768 3.071 0.00213 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 1052.95 on 510 degrees of freedom
## Residual deviance: 813.91 on 507 degrees of freedom
## AIC: 1335.6
##
## Number of Fisher Scoring iterations: 6
#Finalmente solamente hay una interaccion entre factores significativa
levels(plantasdf$Riego)
## [1] "Sin" "Asperción" "Goteo"
labels(plantasdf$Riego)
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
## [13] "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24"
## [25] "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36"
## [37] "37" "38" "39" "40" "41" "42" "43" "44" "45" "46" "47" "48"
## [49] "49" "50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "60"
## [61] "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72"
## [73] "73" "74" "75" "76" "77" "78" "79" "80" "81" "82" "83" "84"
## [85] "85" "86" "87" "88" "89" "90" "91" "92" "93" "94" "95" "96"
## [97] "97" "98" "99" "100" "101" "102" "103" "104" "105" "106" "107" "108"
## [109] "109" "110" "111" "112" "113" "114" "115" "116" "117" "118" "119" "120"
## [121] "121" "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132"
## [133] "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143" "144"
## [145] "145" "146" "147" "148" "149" "150" "151" "152" "153" "154" "155" "156"
## [157] "157" "158" "159" "160" "161" "162" "163" "164" "165" "166" "167" "168"
## [169] "169" "170" "171" "172" "173" "174" "175" "176" "177" "178" "179" "180"
## [181] "181" "182" "183" "184" "185" "186" "187" "188" "189" "190" "191" "192"
## [193] "193" "194" "195" "196" "197" "198" "199" "200" "201" "202" "203" "204"
## [205] "205" "206" "207" "208" "209" "210" "211" "212" "213" "214" "215" "216"
## [217] "217" "218" "219" "220" "221" "222" "223" "224" "225" "226" "227" "228"
## [229] "229" "230" "231" "232" "233" "234" "235" "236" "237" "238" "239" "240"
## [241] "241" "242" "243" "244" "245" "246" "247" "248" "249" "250" "251" "252"
## [253] "253" "254" "255" "256" "257" "258" "259" "260" "261" "262" "263" "264"
## [265] "265" "266" "267" "268" "269" "270" "271" "272" "273" "274" "275" "276"
## [277] "277" "278" "279" "280" "281" "282" "283" "284" "285" "286" "287" "288"
## [289] "289" "290" "291" "292" "293" "294" "295" "296" "297" "298" "299" "300"
## [301] "301" "302" "303" "304" "305" "306" "307" "308" "309" "310" "311" "312"
## [313] "313" "314" "315" "316" "317" "318" "319" "320" "321" "322" "323" "324"
## [325] "325" "326" "327" "328" "329" "330" "331" "332" "333" "334" "335" "336"
## [337] "337" "338" "339" "340" "341" "342" "343" "344" "345" "346" "347" "348"
## [349] "349" "350" "351" "352" "353" "354" "355" "356" "357" "358" "359" "360"
## [361] "361" "362" "363" "364" "365" "366" "367" "368" "369" "370" "371" "372"
## [373] "373" "374" "375" "376" "377" "378" "379" "380" "381" "382" "383" "384"
## [385] "385" "386" "387" "388" "389" "390" "391" "392" "393" "394" "395" "396"
## [397] "397" "398" "399" "400" "401" "402" "403" "404" "405" "406" "407" "408"
## [409] "409" "410" "411" "412" "413" "414" "415" "416" "417" "418" "419" "420"
## [421] "421" "422" "423" "424" "425" "426" "427" "428" "429" "430" "431" "432"
## [433] "433" "434" "435" "436" "437" "438" "439" "440" "441" "442" "443" "444"
## [445] "445" "446" "447" "448" "449" "450" "451" "452" "453" "454" "455" "456"
## [457] "457" "458" "459" "460" "461" "462" "463" "464" "465" "466" "467" "468"
## [469] "469" "470" "471" "472" "473" "474" "475" "476" "477" "478" "479" "480"
## [481] "481" "482" "483" "484" "485" "486" "487" "488" "489" "490" "491" "492"
## [493] "493" "494" "495" "496" "497" "498" "499" "500" "501" "502" "503" "504"
## [505] "505" "506" "507" "508" "509" "510" "511"
length(plantasdf$Riego)
## [1] 511
Riego2 <- c((rep('Sin', 170)), (rep('Aspersión', 170)), (rep('Goteo', 171)))
length(Riego2)
## [1] 511
Riego2T <- transform(Riego2, Riego2 = sample(Riego2))
Riego3 <- Riego2T$Riego2
length((Riego3))
## [1] 511
plantasdf$Riego
## [1] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [9] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [17] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "over"
## [25] "over" "over" "over" "over" "over" "obese" "obese" "obese"
## [33] "obese" "obese" "normal" "normal" "normal" "normal" "normal" "over"
## [41] "over" "over" "over" "obese" "obese" "obese" "obese" "obese"
## [49] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [57] "obese" "obese" "obese" "obese" "obese" "normal" "normal" "normal"
## [65] "normal" "normal" "normal" "normal" "over" "over" "over" "normal"
## [73] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "over"
## [81] "over" "over" "over" "over" "obese" "obese" "obese" "normal"
## [89] "normal" "normal" "normal" "normal" "normal" "normal" "over" "over"
## [97] "over" "over" "over" "over" "over" "over" "obese" "obese"
## [105] "over" "over" "over" "over" "over" "over" "over" "over"
## [113] "over" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [121] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [129] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [137] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [145] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "normal"
## [153] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [161] "over" "over" "normal" "normal" "normal" "normal" "normal" "normal"
## [169] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [177] "normal" "over" "over" "over" "over" "over" "over" "over"
## [185] "over" "over" "over" "over" "over" "over" "over" "over"
## [193] "over" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [201] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [209] "obese" "obese" "obese" "obese" "obese" "normal" "normal" "normal"
## [217] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [225] "normal" "over" "over" "normal" "normal" "normal" "normal" "normal"
## [233] "normal" "normal" "over" "over" "over" "over" "over" "over"
## [241] "over" "over" "over" "obese" "obese" "obese" "normal" "normal"
## [249] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [257] "normal" "over" "over" "over" "over" "over" "obese" "normal"
## [265] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [273] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [281] "over" "obese" "obese" "normal" "normal" "normal" "normal" "normal"
## [289] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [297] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [305] "normal" "normal" "over" "over" "over" "over" "obese" "obese"
## [313] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [321] "normal" "normal" "normal" "normal" "normal" "over" "over" "over"
## [329] "over" "over" "over" "over" "over" "over" "over" "over"
## [337] "over" "over" "over" "over" "over" "over" "over" "over"
## [345] "over" "over" "obese" "obese" "obese" "obese" "obese" "obese"
## [353] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [361] "obese" "obese" "obese" "normal" "normal" "normal" "normal" "normal"
## [369] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [377] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [385] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [393] "normal" "over" "over" "over" "over" "over" "over" "over"
## [401] "over" "over" "over" "over" "over" "over" "over" "over"
## [409] "over" "over" "over" "over" "over" "over" "over" "over"
## [417] "over" "over" "over" "over" "over" "over" "over" "over"
## [425] "over" "over" "over" "over" "over" "over" "over" "over"
## [433] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [441] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [449] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [457] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [465] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [473] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [481] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [489] "obese" "obese" "obese" "obese" "obese" "obese" "obese" "obese"
## [497] "normal" "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## [505] "normal" "normal" "normal" "normal" "normal" "normal" "normal"
## attr(,"levels")
## [1] "Sin" "Asperción" "Goteo"
tapply(plantasdf$Hojas_dañadas,list(plantasdf$Insecticida,plantasdf$Riego),mean)
## normal obese over
## FALSE 0.4184397 0.6893939 0.5436893
## TRUE 0.9523810 3.5142857 2.0270270
names(plantasdf$Riego)
## NULL
barplot(tapply(plantasdf$Hojas_dañadas,list(plantasdf$Insecticida,plantasdf$Riego),mean),col=c("wheat2","wheat4"),
beside=T,ylab="Hojas Dañadas",xlab="Riego")
legend(1.2,3.4,c("Sin Insecticida","Con Insecticida"),fill=c("wheat2","wheat4"))
#
tapla <- as.data.frame(tapply(plantasdf$Hojas_dañadas,list(plantasdf$Insecticida,plantasdf$Riego),mean))
tapply(plantasdf$Hojas_dañadas,list(plantasdf$Insecticida,Riego3),mean)
## Aspersión Goteo Sin
## FALSE 0.6124031 0.5826772 0.4416667
## TRUE 2.1707317 1.9318182 1.6800000
names(Riego3)
## NULL
barplot(tapply(plantasdf$Hojas_dañadas,list(plantasdf$Insecticida,Riego3),mean),col=c("wheat2","wheat4"),
beside=T,ylab="Hojas Dañadas",xlab="Riego")
legend(1.2,3.4,c("Sin Insecticida","Con Insecticida"),fill=c("wheat2","wheat4"))
axis(1, at = 1:3 , labels = c('Sin', 'Asperción', 'Goteo'))
ggplot(data=plantasdf, aes(x =Hojas_dañadas, fill=Insecticida))+
geom_bar()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <- ggplot(data=plantasdf, aes(x=Riego, y=Hojas_dañadas, fill = Insecticida)) +
geom_bar(stat="identity", position = position_dodge())
fig <- ggplotly(p)
fig
## Análisis de la covarianza con datos de conteo.
library(ggplot2)
species<-read.table("species.txt",header=T)
names(species)
## [1] "pH" "Biomass" "Species"
plot(species$Biomass,species$Species)
spp<-split(species$Species,species$pH)
bio<-split(species$Biomass,species$pH)
points(bio[[1]],spp[[1]],pch=16,col="red")
points(bio[[2]],spp[[2]],pch=16,col="green")
points(bio[[3]],spp[[3]],pch=16,col="blue")
legend(c(40,40),legend=c("high","low","medium"),
pch=16,col=c("red","green","blue"),title="pH")
models1<-glm(species$Species~ species$Biomass*species$pH,poisson)
summary(models1)
##
## Call:
## glm(formula = species$Species ~ species$Biomass * species$pH,
## family = poisson)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.4978 -0.7485 -0.0402 0.5575 3.2297
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.76812 0.06153 61.240 < 2e-16 ***
## species$Biomass -0.10713 0.01249 -8.577 < 2e-16 ***
## species$pHlow -0.81557 0.10284 -7.931 2.18e-15 ***
## species$pHmid -0.33146 0.09217 -3.596 0.000323 ***
## species$Biomass:species$pHlow -0.15503 0.04003 -3.873 0.000108 ***
## species$Biomass:species$pHmid -0.03189 0.02308 -1.382 0.166954
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 452.346 on 89 degrees of freedom
## Residual deviance: 83.201 on 84 degrees of freedom
## AIC: 514.39
##
## Number of Fisher Scoring iterations: 4
models1$fitted.values
## 1 2 3 4 5 6 7 8
## 41.175684 35.970380 34.613579 28.433125 27.121046 24.066981 21.157503 19.363736
## 9 10 11 12 13 14 15 16
## 18.118300 15.528289 42.898652 37.924860 33.011842 30.055075 26.437567 24.363380
## 17 18 19 20 21 22 23 24
## 21.440078 19.931134 17.411505 15.832626 39.892219 38.171478 33.751805 30.656874
## 25 26 27 28 29 30 31 32
## 27.799581 24.972593 21.761508 20.311663 16.965367 14.861570 30.332695 25.668353
## 33 34 35 36 37 38 39 40
## 21.802191 20.482226 15.715891 14.788133 10.656746 28.780158 23.569804 20.733298
## 41 42 43 44 45 46 47 48
## 19.875825 15.554476 14.153687 10.080314 28.045963 25.138081 22.790581 18.111032
## 49 50 51 52 53 54 55 56
## 16.337709 15.252368 9.803898 28.950346 25.308858 20.670209 19.092997 16.357246
## 57 58 59 60 61 62 63 64
## 14.078641 13.324425 28.083055 26.460797 18.655001 18.471302 15.274351 13.648141
## 65 66 67 68 69 70 71 72
## 10.026599 10.299976 9.614594 8.165676 6.016636 5.469706 18.904472 16.877355
## 73 74 75 76 77 78 79 80
## 16.142418 12.740788 12.358191 9.026321 9.917957 7.657057 7.301908 5.397441
## 81 82 83 84 85 86 87 88
## 17.753794 18.769240 13.169760 14.278304 12.900038 10.410163 8.733832 7.575999
## 89 90
## 6.100393 5.342587
models2<-glm(species$Species~species$Biomass+species$pH,poisson)
anova(models1,models2,test="Chi")
## Analysis of Deviance Table
##
## Model 1: species$Species ~ species$Biomass * species$pH
## Model 2: species$Species ~ species$Biomass + species$pH
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 84 83.201
## 2 86 99.242 -2 -16.04 0.0003288 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#el p.value de 0.0003288 indica que hay diferencias significativas en las pedientes y por tanto se descarta el modelo 2
Biomasa <- species$Biomass
pH1 <- factor(species$pH)
levels(pH1)
## [1] "high" "low" "mid"
pHs1 <- factor(rep("high",90))
pHs2 <- factor(rep("high",90))
pHs3 <- factor(rep("high",90))
xv1 <- seq(0.1,9,0.1)
yv1 <- predict(object = models1, list(pHs1, xv1))
datfram <- data.frame(xv1, pHs1)
length(xv1)
## [1] 90
length(yv1)
## [1] 90
length(pHs1)
## [1] 90
ajust <- models1$fitted.values
#lines(species$Biomass,exp(ajust),col="red")
#pHs<-factor(rep("low",101))
#yv1<-predict(models1,list(Biomasa=xv1, pH1=pHs1))
#lines(species$Biomass,exp(ajust),col="green")
#pHs<-factor(rep("mid",101))
#yv1<-predict(models1,list(species$Biomass=xv1,species$pH=pHs1))
#lines(species$Biomass,exp(ajust),col="blue")
#df <-data.frame(xv1, pHs1)
ajustdf<-data.frame(ajust, Biomasa)
plot1 <- ggplot(data = species, aes(x =species$Biomass, y = species$Species))+
geom_point(aes(colour = pH))
plot1
## Warning: Use of `species$Biomass` is discouraged. Use `Biomass` instead.
## Warning: Use of `species$Species` is discouraged. Use `Species` instead.
plot2 <- ggplot(data = ajustdf, aes(x =Biomasa, y = ajust))+
geom_line(aes(colour = species$pH))
plot2
plot3 <- ggplot(data = species, aes(x =Biomass, y = Species))+
geom_point(aes(colour = pH))+
geom_line(data = ajustdf, aes(x =Biomasa, y = ajust, colour = species$pH))
plot3
case.book<-read.table("cases.txt",header=T)
names(case.book)
## [1] "cases"
frequencies<-table(case.book$cases)
frequencies
##
## 0 1 2 3 4 5 6 7 8 9 10
## 34 14 10 7 4 5 2 1 1 1 1
mean(case.book$cases)
## [1] 1.775
windows(7,4)
par(mfrow=c(1,2))
barplot(frequencies,ylab="Frequency",xlab="Cases",col="green4", main="Cases")
barplot(dpois(0:10,1.775)*80,names=as.character(0:10),
ylab="Frequency",xlab="Cases",col="green3",main="Poisson")
ratio<-var(case.book$cases)/mean(case.book$cases) # Altamente agregados, proporción mayor a 1
ratio
## [1] 2.99483
## Un buen candidato en vez de poisson es modelo binomial negativo
media <- mean(case.book$cases)
vari <- var(case.book$cases)
k<- (media*media)/(vari-media)
k
## [1] 0.8898003
#distribució bionomial negativa
exp<-dnbinom(0:10,1,mu=1.775)*80
both<-numeric(22)
both[1:22 %% 2 != 0]<-frequencies
both[1:22 %% 2 == 0]<-exp
labels<-character(22)
labels[1:22 %% 2 == 0]<-as.character(0:10)
windows(7,7)
barplot(both,col=rep(c("red4","blue4"),11),names=labels,ylab="Frequency",
xlab="Cases")
legend(c(10,10),c("observed","expected") ,fill=c("red4","blue4"))
exp
## [1] 28.8288288 18.4400617 11.7949944 7.5445460 4.8257907 3.0867670
## [7] 1.9744185 1.2629164 0.8078114 0.5167082 0.3305070
cs<-factor(0:10)
levels(cs)[6:11]<-"5+"
levels(cs)
## [1] "0" "1" "2" "3" "4" "5+"
ef<-as.vector(tapply(exp,cs,sum))
of<-as.vector(tapply(frequencies,cs,sum))
sum((of-ef)*(of-ef)/ef)
## [1] 3.594145
1-pchisq(3.594145,3)
## [1] 0.3087555
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:plotly':
##
## select
data(quine)
names(quine)
## [1] "Eth" "Sex" "Age" "Lrn" "Days"
Days <- quine$Days
Eth <- quine$Eth
Sex <- quine$Sex
Age <- quine$Age
Lrn <- quine$Lrn
#moedelo inicial general
model1<-glm(Days~Eth*Sex*Age*Lrn,poisson)
summary(model1)
##
## Call:
## glm(formula = Days ~ Eth * Sex * Age * Lrn, family = poisson)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -7.3872 -2.5129 -0.4205 1.7424 6.6783
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.0564 0.1085 28.178 < 2e-16 ***
## EthN -0.1386 0.1590 -0.872 0.383394
## SexM -0.4914 0.1648 -2.982 0.002860 **
## AgeF1 -0.6227 0.1712 -3.638 0.000275 ***
## AgeF2 -2.3632 0.7154 -3.303 0.000955 ***
## AgeF3 -0.3784 0.1393 -2.717 0.006592 **
## LrnSL -1.9577 0.5875 -3.333 0.000860 ***
## EthN:SexM -0.7524 0.2682 -2.806 0.005021 **
## EthN:AgeF1 0.1029 0.2408 0.427 0.669209
## EthN:AgeF2 -0.5546 1.2350 -0.449 0.653410
## EthN:AgeF3 0.0633 0.2008 0.315 0.752564
## SexM:AgeF1 0.4092 0.3038 1.347 0.178074
## SexM:AgeF2 3.1098 0.7296 4.262 2.02e-05 ***
## SexM:AgeF3 1.1145 0.2001 5.570 2.55e-08 ***
## EthN:LrnSL 2.2588 0.6314 3.578 0.000347 ***
## SexM:LrnSL 1.5900 0.6305 2.522 0.011673 *
## AgeF1:LrnSL 2.6421 0.6059 4.361 1.30e-05 ***
## AgeF2:LrnSL 4.8585 0.9212 5.274 1.33e-07 ***
## AgeF3:LrnSL NA NA NA NA
## EthN:SexM:AgeF1 -0.3105 0.5432 -0.572 0.567587
## EthN:SexM:AgeF2 0.3469 1.2620 0.275 0.783401
## EthN:SexM:AgeF3 0.8329 0.3122 2.668 0.007627 **
## EthN:SexM:LrnSL -0.1639 0.7024 -0.233 0.815496
## EthN:AgeF1:LrnSL -3.5493 0.6715 -5.286 1.25e-07 ***
## EthN:AgeF2:LrnSL -3.3315 1.3856 -2.404 0.016202 *
## EthN:AgeF3:LrnSL NA NA NA NA
## SexM:AgeF1:LrnSL -2.4285 0.7100 -3.420 0.000626 ***
## SexM:AgeF2:LrnSL -4.1914 0.9555 -4.387 1.15e-05 ***
## SexM:AgeF3:LrnSL NA NA NA NA
## EthN:SexM:AgeF1:LrnSL 2.1711 0.8924 2.433 0.014985 *
## EthN:SexM:AgeF2:LrnSL 2.1029 1.4330 1.467 0.142254
## EthN:SexM:AgeF3:LrnSL NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 2073.5 on 145 degrees of freedom
## Residual deviance: 1173.9 on 118 degrees of freedom
## AIC: 1818.4
##
## Number of Fisher Scoring iterations: 5
#eiste sobre disperción por lo que se usa quasi-Poisson
model2<-glm(Days~Eth*Sex*Age*Lrn,quasipoisson)
summary(model2)
##
## Call:
## glm(formula = Days ~ Eth * Sex * Age * Lrn, family = quasipoisson)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -7.3872 -2.5129 -0.4205 1.7424 6.6783
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.0564 0.3346 9.135 2.22e-15 ***
## EthN -0.1386 0.4904 -0.283 0.7780
## SexM -0.4914 0.5082 -0.967 0.3356
## AgeF1 -0.6227 0.5281 -1.179 0.2407
## AgeF2 -2.3632 2.2066 -1.071 0.2864
## AgeF3 -0.3784 0.4296 -0.881 0.3802
## LrnSL -1.9577 1.8120 -1.080 0.2822
## EthN:SexM -0.7524 0.8272 -0.910 0.3649
## EthN:AgeF1 0.1029 0.7427 0.139 0.8901
## EthN:AgeF2 -0.5546 3.8094 -0.146 0.8845
## EthN:AgeF3 0.0633 0.6194 0.102 0.9188
## SexM:AgeF1 0.4092 0.9372 0.437 0.6632
## SexM:AgeF2 3.1098 2.2506 1.382 0.1696
## SexM:AgeF3 1.1145 0.6173 1.806 0.0735 .
## EthN:LrnSL 2.2588 1.9474 1.160 0.2484
## SexM:LrnSL 1.5900 1.9448 0.818 0.4152
## AgeF1:LrnSL 2.6421 1.8688 1.414 0.1601
## AgeF2:LrnSL 4.8585 2.8413 1.710 0.0899 .
## AgeF3:LrnSL NA NA NA NA
## EthN:SexM:AgeF1 -0.3105 1.6756 -0.185 0.8533
## EthN:SexM:AgeF2 0.3469 3.8928 0.089 0.9291
## EthN:SexM:AgeF3 0.8329 0.9629 0.865 0.3888
## EthN:SexM:LrnSL -0.1639 2.1666 -0.076 0.9398
## EthN:AgeF1:LrnSL -3.5493 2.0712 -1.714 0.0892 .
## EthN:AgeF2:LrnSL -3.3315 4.2739 -0.779 0.4373
## EthN:AgeF3:LrnSL NA NA NA NA
## SexM:AgeF1:LrnSL -2.4285 2.1901 -1.109 0.2697
## SexM:AgeF2:LrnSL -4.1914 2.9472 -1.422 0.1576
## SexM:AgeF3:LrnSL NA NA NA NA
## EthN:SexM:AgeF1:LrnSL 2.1711 2.7527 0.789 0.4319
## EthN:SexM:AgeF2:LrnSL 2.1029 4.4203 0.476 0.6351
## EthN:SexM:AgeF3:LrnSL NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 9.514226)
##
## Null deviance: 2073.5 on 145 degrees of freedom
## Residual deviance: 1173.9 on 118 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 5
ftable(table(Eth,Sex,Age,Lrn))
## Lrn AL SL
## Eth Sex Age
## A F F0 4 1
## F1 5 10
## F2 1 8
## F3 9 0
## M F0 5 3
## F1 2 3
## F2 7 4
## F3 7 0
## N F F0 4 1
## F1 6 11
## F2 1 9
## F3 10 0
## M F0 6 3
## F1 2 7
## F2 7 3
## F3 7 0
#simplificacion del modelo
model3<-update(model2,~. - Age:Lrn)
anova(model2,model3,test="F")
## Analysis of Deviance Table
##
## Model 1: Days ~ Eth * Sex * Age * Lrn
## Model 2: Days ~ Eth + Sex + Age + Lrn + Eth:Sex + Eth:Age + Sex:Age +
## Eth:Lrn + Sex:Lrn + Eth:Sex:Age + Eth:Sex:Lrn + Eth:Age:Lrn +
## Sex:Age:Lrn + Eth:Sex:Age:Lrn
## Resid. Df Resid. Dev Df Deviance F Pr(>F)
## 1 118 1173.9
## 2 118 1173.9 0 0
summary(model3)
##
## Call:
## glm(formula = Days ~ Eth + Sex + Age + Lrn + Eth:Sex + Eth:Age +
## Sex:Age + Eth:Lrn + Sex:Lrn + Eth:Sex:Age + Eth:Sex:Lrn +
## Eth:Age:Lrn + Sex:Age:Lrn + Eth:Sex:Age:Lrn, family = quasipoisson)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -7.3872 -2.5129 -0.4205 1.7424 6.6783
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.0564 0.3346 9.135 2.22e-15 ***
## EthN -0.1386 0.4904 -0.283 0.7780
## SexM -0.4914 0.5082 -0.967 0.3356
## AgeF1 -0.6227 0.5281 -1.179 0.2407
## AgeF2 -2.3632 2.2066 -1.071 0.2864
## AgeF3 -0.3784 0.4296 -0.881 0.3802
## LrnSL -1.9577 1.8120 -1.080 0.2822
## EthN:SexM -0.7524 0.8272 -0.910 0.3649
## EthN:AgeF1 0.1029 0.7427 0.139 0.8901
## EthN:AgeF2 -0.5546 3.8094 -0.146 0.8845
## EthN:AgeF3 0.0633 0.6194 0.102 0.9188
## SexM:AgeF1 0.4092 0.9372 0.437 0.6632
## SexM:AgeF2 3.1098 2.2506 1.382 0.1696
## SexM:AgeF3 1.1145 0.6173 1.806 0.0735 .
## EthN:LrnSL 2.2588 1.9474 1.160 0.2484
## SexM:LrnSL 1.5900 1.9448 0.818 0.4152
## EthN:SexM:AgeF1 -0.3105 1.6756 -0.185 0.8533
## EthN:SexM:AgeF2 0.3469 3.8928 0.089 0.9291
## EthN:SexM:AgeF3 0.8329 0.9629 0.865 0.3888
## EthN:SexM:LrnSL -0.1639 2.1666 -0.076 0.9398
## EthA:AgeF1:LrnSL 2.6421 1.8688 1.414 0.1601
## EthN:AgeF1:LrnSL -0.9072 0.8930 -1.016 0.3117
## EthA:AgeF2:LrnSL 4.8585 2.8413 1.710 0.0899 .
## EthN:AgeF2:LrnSL 1.5270 3.1927 0.478 0.6333
## EthA:AgeF3:LrnSL NA NA NA NA
## EthN:AgeF3:LrnSL NA NA NA NA
## SexM:AgeF1:LrnSL -2.4285 2.1901 -1.109 0.2697
## SexM:AgeF2:LrnSL -4.1914 2.9472 -1.422 0.1576
## SexM:AgeF3:LrnSL NA NA NA NA
## EthN:SexM:AgeF1:LrnSL 2.1711 2.7527 0.789 0.4319
## EthN:SexM:AgeF2:LrnSL 2.1029 4.4203 0.476 0.6351
## EthN:SexM:AgeF3:LrnSL NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasipoisson family taken to be 9.514226)
##
## Null deviance: 2073.5 on 145 degrees of freedom
## Residual deviance: 1173.9 on 118 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 5
ftable(tapply(Days,list(Eth,Sex,Lrn),mean))
## AL SL
##
## A F 14.47368 27.36842
## M 22.28571 20.20000
## N F 13.14286 7.00000
## M 13.36364 17.00000