-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclase11_diplomado.Rmd
More file actions
97 lines (77 loc) · 2.05 KB
/
Copy pathclase11_diplomado.Rmd
File metadata and controls
97 lines (77 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: "clase_11_diplomado"
author: "Luis Daniel Chavarría"
date: "6/3/2020"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Librerías
```{r}
library(tidyverse)
library(lubridate)
library(plotly)
library(broom)
```
# Lectura de datos
```{r}
diplomado <- read_csv2("database/clean_diplomate.csv") %>%
filter(!(estotal == "SD" | estotal == "N/A")) %>%
mutate(estb1 = as.numeric(estb1),
estb3 = as.numeric(estb3),
estotal = as.numeric(estotal),
estuce = as.numeric(estuce),
estuci = as.numeric(estuci),
atencion = as.character(atencion),
id = as.character(id),
edad = as.numeric(edad),
genero = as_factor(genero),
cronico = as_factor(cronico),
segcronico = as_factor(segcronico),
eps = as_factor(eps),
espinter = as_factor(espinter),
urg = as_factor(urg),
tipurg = as_factor(tipurg),
inter = as_factor(inter),
ordurg = as_factor(ordurg),
cirugia = as_factor(cirugia),
proc = as_factor(proc),
pisodes = as_factor(pisodes),
esp = as_factor(esp),
anoing = as_date(anoing),
mesing = as.character(mesing),
diaing = as.character(diaing)
)
```
# Ajuste de regresión lineal
```{r}
glimpse(diplomado)
age_fit <- lm(estotal ~ edad, data = diplomado)
tidy(age_fit)
glance(age_fit)
```
# Predicción
```{r}
datos_nuevos <- tibble(edad = c(23, 35))
predict(age_fit, newdata = datos_nuevos)
```
# Reto
```{r}
cronicos_piso2 <- diplomado %>%
filter(cronico == "Sí", pisodes == "Piso 2", genero == "Masculino")
modelo_cronicos <- lm(estotal ~ estb3, data = cronicos_piso2)
modelo_cronicos %>%
tidy()
modelo_cronicos %>%
glance()
ggplot(cronicos_piso2, aes(x = estb3, y = estotal)) +
geom_point() +
geom_smooth(method = "lm")
cor(cronicos_piso2$estotal, modelo_cronicos$fitted.values)
```
```{r}
summary(lm(estotal ~ estb1*estb3*cronico, data = diplomado))
```