Skip to content

Commit

Permalink
agrega codigo base para inferencia causal
Browse files Browse the repository at this point in the history
  • Loading branch information
agarbuno committed Jun 2, 2021
1 parent afcc8a1 commit c6af604
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions notas/09-bases-inferencia-causal.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Inferencia causal


```{r setup, include=FALSE, message=FALSE}
library(tidyverse)
library(cmdstanr)
library(rstanarm)
library(arm)
library(bayesplot)
library(loo)
library(patchwork)
library(scales)
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning=FALSE,
fig.align = 'center', fig.width = 5, fig.height=3, cache = TRUE)
comma <- function(x) format(x, digits = 2, big.mark = ",")
theme_set(theme_linedraw())
color.blues <- c(NA,"#BDD7E7", "#6BAED6", "#3182BD", "#08519C", "#074789", "#063e77", "#053464")
color.itam <- c("#00362b", "#00503f", "#006953", "#008367", "#009c7b", "#00b68f")
sin_lineas <- theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
sin_leyenda <- theme(legend.position = "none")
sin_ejes <- theme(axis.ticks = element_blank(),
axis.text = element_blank())
options(mc.cores = 4)
```

```{r}
data <- tibble(female = factor(rep(rep(c(1,0), each = 2), 2)),
age = rep(c(4,5,6,7), each = 2) * 10,
treatment = factor(rep(c(0,1), each = 4)),
outcome = rep(c(140, 150, 155, 160), each = 2))
model.1 <- stan_glm(outcome ~ treatment, data = data, refresh = 0)
summary(model.1)
```
```{r}
model.2 <- stan_glm(outcome ~ female + treatment + treatment:female,
data = data,
refresh = 0)
model.2
summary(model.2)
```

```{r}
data <- data %>%
mutate(treatment.rand = rep(c(0,1), 4))
model.3 <- stan_glm(outcome ~ female + treatment.rand + treatment.rand:female,
data = data,
refresh = 0)
summary(model.3)
```

0 comments on commit c6af604

Please sign in to comment.