-
Notifications
You must be signed in to change notification settings - Fork 13
/
io29a-chisq_example.Rmd
executable file
·82 lines (62 loc) · 1.95 KB
/
io29a-chisq_example.Rmd
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
---
title: "Untitled"
author: "Peter Higgins"
date: "3/21/2019"
output:
word_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(arsenal)
library(tidyverse)
library(janitor)
library(corrplot)
```
```{r glimpse, echo=FALSE}
#glimpse(mockstudy)
```
```{r table, warning=FALSE}
mockstudy %>%
tabyl(arm, fu.stat) %>%
column_to_rownames('arm') %>%
chisq.test() ->
results
results$statistic
results$parameter
```
## Study Results
This is an R Markdown document. <br>
In the evaluation of followup status by study arm, the null hypothesis of independence was rejected, with a chi-squared statistic of `r round(results$statistic,2)`, with `r results$parameter` degrees of freedom, and a p value of `r results$p.value`, using the `r results$method` method.
```{r housetask, echo=FALSE}
file_path <- "http://www.sthda.com/sthda/RDoc/data/housetasks.txt"
housetasks <- read.delim(file_path, row.names = 1)
housetasks %>%
chisq.test()
```
```{r corr, warning=FALSE, echo=FALSE}
file_path <- "http://www.sthda.com/sthda/RDoc/data/housetasks.txt"
housetasks <- read.delim(file_path, row.names = 1)
housetasks %>%
chisq.test() ->
results
corrplot(results$residuals, is.cor = FALSE)
```
In the evaluation of household tasks by person responsible, the null hypothesis of independence was rejected, with a chi-squared statistic of `r round(results$statistic,2)`, with `r results$parameter` degrees of freedom, and a p value of `r results$p.value`, using the `r results$method` method.
```{r as_dataframe}
housetasks %>%
as.data.frame() %>%
rownames_to_column("Task") %>%
filter(Task=="Finances" | Task=="Official") %>%
select(Task, Wife, Husband) %>%
column_to_rownames("Task") %>%
chisq.test()
```
```{r percent, warning=FALSE, echo=FALSE}
housetasks %>%
chisq.test() ->
results
contrib <- 100*results$residuals^2/results$statistic
round(contrib, 3)
corrplot(contrib, is.cor = FALSE)
```