Prueba de independencia utilizando \(\chi2\) para una tabla de contingencia.
\[H_0:la\ frecuencia\ de\ daños\ es\ independiente\ de\ la\ especie\]
library(pander)
#definimos matriz frecuencias observadas
#secuencia de datos por especies
mfo <- matrix(c(9,5,30,5,0,161,2,0,21), ncol = 3, byrow = TRUE)
#data frame desde matriz de datos
fo <- as.data.frame(mfo)
rownames(fo) <- c("T. heterophylla","S. mahogani","C. citrinus")
colnames(fo) <- c("snap","uprooting","broken branches")
print(fo)
## snap uprooting broken branches
## T. heterophylla 9 5 30
## S. mahogani 5 0 161
## C. citrinus 2 0 21
#prueba de Ho: independencia
ind.test <- chisq.test(fo)
## Warning in chisq.test(fo): Chi-squared approximation may be incorrect
pander(ind.test)
Test statistic | df | P value |
---|---|---|
40.18 | 4 | 3.966e-08 * * * |
El valor de P nos permite rechazar la \(H_0\). En la siguiente gráfica podemos apreciar que T. heterophylla es diferente en la distribución de la frecuencia de daños.
library(BoutrosLab.plotting.general)
## Loading required package: lattice
## Loading required package: latticeExtra
## Loading required package: RColorBrewer
## Loading required package: cluster
## Loading required package: hexbin
## Loading required package: grid
##
## Attaching package: 'BoutrosLab.plotting.general'
## The following object is masked from 'package:stats':
##
## dist
library(vcd)
##
## Attaching package: 'vcd'
## The following object is masked from 'package:latticeExtra':
##
## rootogram
#gráfica de contingencia
mosaic(mfo, shade = TRUE, legend = FALSE,
labeling_args = list(set_varnames = c(A = "Species", B = "Damage")),
set_labels = list(A = c("T.h.","S.m.","C.c."), B = c("S","U","BB")))