Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ad9c48

Browse files
committed
demos completed 8/44
0 parents  commit 7ad9c48

File tree

3 files changed

+2505
-0
lines changed

3 files changed

+2505
-0
lines changed

examples.Rmd

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "R Notebook"
3+
output: html_notebook
4+
---
5+
6+
```{r}
7+
library(tidyverse)
8+
library(lmtest)
9+
library
10+
```
11+
12+
```{r}
13+
# hrs_df <- read_csv("hrs_analyze.csv") %>%
14+
# select(female, age_2014, depress_dx, bp_dx) %>%
15+
# drop_na()
16+
hrs_df <- read_csv("hrs_analyze.csv") %>%
17+
select(female, age_2014, depress_dx, bp_dx)
18+
hrs_df
19+
```
20+
21+
```{r}
22+
hrs_df %>%
23+
mutate(bp_dx = factor(bp_dx), depress_dx = factor(depress_dx)) %>%
24+
group_by(depress_dx, bp_dx) %>%
25+
summarize(count = n()) %>%
26+
ggplot() +
27+
geom_bar(aes(x = depress_dx, y = count, fill = bp_dx), stat = "identity", position = "fill")
28+
```
29+
30+
```{r}
31+
depress_dx_fit <- glm(depress_dx ~ bp_dx, data = hrs_df, family=binomial)
32+
depress_dx_fit
33+
```
34+
35+
```{r}
36+
depress_dx_fit %>% summary()
37+
```
38+
39+
```{r}
40+
depress_dx_fit %>% coefficients() %>% exp()
41+
```
42+
43+
```{r}
44+
depress_dx_multi_fit <- glm(depress_dx ~ bp_dx + age_2014 + female, data = hrs_df, family=binomial)
45+
depress_dx_multi_fit
46+
```
47+
48+
```{r}
49+
depress_dx_multi_fit %>% summary()
50+
```
51+
52+
```{r}
53+
lrtest(depress_dx_fit, depress_dx_multi_fit)
54+
```
55+
56+
```{r}
57+
depress_dx_multi_fit %>% vif()
58+
```
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+

0 commit comments

Comments
 (0)