lbw<-read.csv2("Data/lbw.csv",sep=",", dec = ".")
str(lbw)
## 'data.frame': 189 obs. of 11 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ low : int 0 0 0 0 0 0 0 0 0 0 ...
## $ smoke: int 0 0 1 1 1 0 0 0 1 1 ...
## $ race : int 2 3 1 1 1 3 1 3 1 1 ...
## $ age : int 19 33 20 21 18 21 22 17 29 26 ...
## $ lwt : int 182 155 105 108 107 124 118 103 123 113 ...
## $ ptl : int 0 0 0 0 0 0 0 0 0 0 ...
## $ ht : int 0 0 0 0 0 0 0 0 0 0 ...
## $ ui : int 1 0 0 1 1 0 0 0 0 0 ...
## $ ftv : int 0 3 1 2 0 0 1 1 1 0 ...
## $ bwt : int 2523 2551 2557 2594 2600 2622 2637 2637 2663 2665 ...
lbw$low<-as.factor(lbw$low)
lbw$smoke<-as.factor(lbw$smoke)
lbw$race<-as.factor(lbw$race)
lbw$ht<-as.factor(lbw$ht)
lbw$ui<-as.factor(lbw$ui)
str(lbw)
## 'data.frame': 189 obs. of 11 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ low : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## $ smoke: Factor w/ 2 levels "0","1": 1 1 2 2 2 1 1 1 2 2 ...
## $ race : Factor w/ 3 levels "1","2","3": 2 3 1 1 1 3 1 3 1 1 ...
## $ age : int 19 33 20 21 18 21 22 17 29 26 ...
## $ lwt : int 182 155 105 108 107 124 118 103 123 113 ...
## $ ptl : int 0 0 0 0 0 0 0 0 0 0 ...
## $ ht : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## $ ui : Factor w/ 2 levels "0","1": 2 1 1 2 2 1 1 1 1 1 ...
## $ ftv : int 0 3 1 2 0 0 1 1 1 0 ...
## $ bwt : int 2523 2551 2557 2594 2600 2622 2637 2637 2663 2665 ...
##Prueba de Hipotesis
#vamos a ver si se acepta o rechaza la hipótesis nula, para ello realizamos una prueba de hipótesis de dos colas
## Smoke, tabaquismo como variable de incidiencia para el resultado de bajo peso al nacer
# Fuma 1 (SI)
# NO fumaN 0 (NO)
#HIPOTESIS : dos colas
#H0:Hipotesis Nula: La varianza fuma de r1 = la varianza fuma r2
#Ha:La varianza fuma de r1 =/ (diferente) la varianza fuma r2
#Alpha=0.05
## Se crean los dos grupos POR TIPO DE CONDICION
hyp=subset(lbw, lbw$smoke=="1")# datos fuman
head(hyp)
## X low smoke race age lwt ptl ht ui ftv bwt
## 3 3 0 1 1 20 105 0 0 0 1 2557
## 4 4 0 1 1 21 108 0 0 1 2 2594
## 5 5 0 1 1 18 107 0 0 1 0 2600
## 9 9 0 1 1 29 123 0 0 0 1 2663
## 10 10 0 1 1 26 113 0 0 0 0 2665
## 15 15 0 1 1 18 100 0 0 0 0 2769
nhyp=subset(lbw, lbw$smoke=="0") # datos no fuman
head(nhyp)
## X low smoke race age lwt ptl ht ui ftv bwt
## 1 1 0 0 2 19 182 0 0 1 0 2523
## 2 2 0 0 3 33 155 0 0 0 3 2551
## 6 6 0 0 3 21 124 0 0 0 0 2622
## 7 7 0 0 1 22 118 0 0 0 1 2637
## 8 8 0 0 3 17 103 0 0 0 1 2637
## 11 11 0 0 3 19 95 0 0 0 0 2722
hyp=subset(lbw, lbw$smoke=="1")# datos fuma
head(hyp)
## X low smoke race age lwt ptl ht ui ftv bwt
## 3 3 0 1 1 20 105 0 0 0 1 2557
## 4 4 0 1 1 21 108 0 0 1 2 2594
## 5 5 0 1 1 18 107 0 0 1 0 2600
## 9 9 0 1 1 29 123 0 0 0 1 2663
## 10 10 0 1 1 26 113 0 0 0 0 2665
## 15 15 0 1 1 18 100 0 0 0 0 2769
nhyp=subset(lbw, lbw$smoke=="0") # datos no fuma
head(nhyp)
## X low smoke race age lwt ptl ht ui ftv bwt
## 1 1 0 0 2 19 182 0 0 1 0 2523
## 2 2 0 0 3 33 155 0 0 0 3 2551
## 6 6 0 0 3 21 124 0 0 0 0 2622
## 7 7 0 0 1 22 118 0 0 0 1 2637
## 8 8 0 0 3 17 103 0 0 0 1 2637
## 11 11 0 0 3 19 95 0 0 0 0 2722
boxplot (hyp$bwt)
hist(hyp$bwt, col="aquamarine3")
boxplot (nhyp$bwt)
hist(nhyp$bwt, col="aquamarine3")
qqnorm(hyp$bwt, col="aquamarine3",pch = 19)
qqline(nhyp$bwt,col="red")
summary(hyp$bwt)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 709 2370 2776 2772 3246 4238
summary(nhyp$bwt)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1021 2509 3100 3055 3622 4990
var.test(hyp$bwt,nhyp$bwt,)
##
## F test to compare two variances
##
## data: hyp$bwt and nhyp$bwt
## F = 0.769, num df = 73, denom df = 114, p-value = 0.2275
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.511079 1.179748
## sample estimates:
## ratio of variances
## 0.7690003
##Interpretacion: Con una confiabilidad del 95% se espera que el cociente de las varianzas de la variable Fumar o no fuma se encuentren entre 0.51 y 1.17, como el valor del p value es mayor al grado de significancia No hay evidencia suficiente para rechazar la hipotesis nula.
#Normalidad
shapiro.test(hyp$bwt)
##
## Shapiro-Wilk normality test
##
## data: hyp$bwt
## W = 0.98296, p-value = 0.4199
#Como p-value=0.4199 es grande : es decir mayor del nivel significancia 0.05, entonces NO SE RECHAZA la hipótesis nula. #Por lo tanto es correcto afirmar que no existe evidencia estadistica suficiente para refutar el hecho de que la muestra observada provenga de una distribución normal.
##T.test
t.test(hyp$bwt,nhyp$bwt,var.equal = TRUE,conf.level = 0.95)
##
## Two Sample t-test
##
## data: hyp$bwt and nhyp$bwt
## t = -2.6428, df = 187, p-value = 0.00892
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -493.65152 -71.66693
## sample estimates:
## mean of x mean of y
## 2772.297 3054.957
#Interpretacion: El p-value es 0.00892 menor a 0.05, se puede rechazar la hipotesis nula con la prueba T,
##CONCLUSION: el promedio de la variable fumar o no fumar de las madres no son iguales, por lo tanto es posible inferir que un grupo incide sobre el otro, dato de interés para la salud pública dado a que se podrian advertir como un posible factor de riesgo para bajo peso al nacer de los bebés.