Instrucciones

Con los datos que se importan a continuación, concluir si es el tipo tratamiento médico (T: A,B), o la clínica (Clinic: uno,dos) lo que explica el pronóstico (positivo, negativo).

packages

if(!require(googlesheets4)){install.packages("googlesheets4")}
if(!require(googledrive)){install.packages("googledrive")}
if(!require(ggplot2)){install.packages("ggplot2")}
if(!require(DescTools)){install.packages("DescTools")}
if(!require(MASS)){install.packages("MASS")}
if(!require(binom)){install.packages("binom")}
if(!require(scales)){install.packages("scales")}
##
library(googlesheets4)
library(googledrive)
library(ggplot2)
library(DescTools)
library(MASS)
library(binom)
library(scales)

Table Treatment & Clinics

ss= "https://docs.google.com/spreadsheets/d/1RFCYi7rjRPcbzcB01Nq3jgtc_o21LaDU8yFU41gjQKs/edit?usp=sharing"
hoja= "clinicTrat"
rango = "B4:E8"
#
gs4_deauth()
trat <- read_sheet(ss,
                   sheet=hoja,
                   range=rango,
                   col_names=TRUE
                   )
## Reading from "ClinicaxTratamiento"
## Range "'clinicTrat'!B4:E8"
trat$Clinic <- as.factor(trat$Clinic)
trat$T <- as.factor(trat$T) 
#
trat$pr.exito <- trat$Posit / 
  (trat$Posit+trat$Negat)           # Proporción de éxito (resultado positivo al tratamiento)
trat
## # A tibble: 4 x 5
##   Clinic T     Posit Negat pr.exito
##   <fct>  <fct> <dbl> <dbl>    <dbl>
## 1 dos    A         4    16    0.2  
## 2 dos    B        22    32    0.407
## 3 uno    A         8    32    0.2  
## 4 uno    B        12     8    0.6

ggplot

ggplot( aes( x= T, y= pr.exito, fill = T), data= trat) + 
  geom_bar(stat="identity", position= "dodge")

ggplot( aes( x= Clinic, y= pr.exito), data= trat) + 
  geom_bar(stat="identity", position= "dodge")

p <- ggplot( aes( x= Clinic, y= pr.exito, fill = T), data= trat) + 
  geom_bar(stat="identity", position= "dodge")
p

Odds

trat$Odds.exito <- trat$Posit / trat$Negat
trat
## # A tibble: 4 x 6
##   Clinic T     Posit Negat pr.exito Odds.exito
##   <fct>  <fct> <dbl> <dbl>    <dbl>      <dbl>
## 1 dos    A         4    16    0.2        0.25 
## 2 dos    B        22    32    0.407      0.688
## 3 uno    A         8    32    0.2        0.25 
## 4 uno    B        12     8    0.6        1.5

glm

# Variable respuesta es binaria (dos columnas)
Y.trat <- cbind(trat$Posit, trat$Negat)
Y.trat
##      [,1] [,2]
## [1,]    4   16
## [2,]   22   32
## [3,]    8   32
## [4,]   12    8

Modelo comparando clínicas

glm.clinic <- glm( Y.trat ~ trat$Clinic, family=binomial)
summary(glm.clinic)
## 
## Call:
## glm(formula = Y.trat ~ trat$Clinic, family = binomial)
## 
## Deviance Residuals: 
##       1        2        3        4  
## -1.4844   0.8536  -1.8696   2.4359  
## 
## Coefficients:
##                Estimate Std. Error z value Pr(>|z|)  
## (Intercept)    -0.61310    0.24351  -2.518   0.0118 *
## trat$Clinicuno -0.08004    0.36646  -0.218   0.8271  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 12.409  on 3  degrees of freedom
## Residual deviance: 12.361  on 2  degrees of freedom
## AIC: 30.97
## 
## Number of Fisher Scoring iterations: 4

Modelo comparando tratamientos médicos

glm.trat <- glm( Y.trat ~ trat$T, family=binomial)
summary(glm.trat)
## 
## Call:
## glm(formula = Y.trat ~ trat$T, family = binomial)
## 
## Deviance Residuals: 
##       1        2        3        4  
##  0.0000  -0.7704   0.0000   1.2599  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -1.3863     0.3227  -4.295 1.74e-05 ***
## trat$TB       1.2238     0.3982   3.073  0.00212 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 12.409  on 3  degrees of freedom
## Residual deviance:  2.181  on 2  degrees of freedom
## AIC: 20.79
## 
## Number of Fisher Scoring iterations: 3

Modelo en busca de interacción: Clinic * T

glm <- glm( Y.trat ~ trat$T * trat$Clinic, family=binomial)
summary(glm)
## 
## Call:
## glm(formula = Y.trat ~ trat$T * trat$Clinic, family = binomial)
## 
## Deviance Residuals: 
## [1]  0  0  0  0
## 
## Coefficients:
##                          Estimate Std. Error z value Pr(>|z|)  
## (Intercept)            -1.386e+00  5.590e-01  -2.480   0.0131 *
## trat$TB                 1.012e+00  6.239e-01   1.622   0.1049  
## trat$Clinicuno         -5.861e-13  6.847e-01   0.000   1.0000  
## trat$TB:trat$Clinicuno  7.802e-01  8.682e-01   0.899   0.3689  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1.2409e+01  on 3  degrees of freedom
## Residual deviance: 8.8818e-15  on 0  degrees of freedom
## AIC: 22.609
## 
## Number of Fisher Scoring iterations: 3

Modelo aditivo: Clinic + T

## 
## Call:
## glm(formula = Y.trat ~ trat$T + trat$Clinic, family = binomial)
## 
## Deviance Residuals: 
##       1        2        3        4  
##  0.6023  -0.2762  -0.3845   0.4521  
## 
## Coefficients:
##                Estimate Std. Error z value Pr(>|z|)    
## (Intercept)     -1.7352     0.4507  -3.850 0.000118 ***
## trat$TB          1.4369     0.4458   3.223 0.001268 ** 
## trat$Clinicuno   0.4987     0.4277   1.166 0.243581    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 12.40871  on 3  degrees of freedom
## Residual deviance:  0.79129  on 1  degrees of freedom
## AIC: 21.4
## 
## Number of Fisher Scoring iterations: 4

Refeencias

Agresti, A., & Coull, B. A. (1998). Approximate is better than “exact” for interval estimation of binomial proportions. The American Statistician, 52(2), 119–126.