---
title: "Chi-Squared Distribution"
output: html_document
---

```{r}
rchisq(10, df=1)
qchisq(0.95, df=1)
pchisq(3.841459, df=1)
```


```{r}
# Goodness of fit with specified probabilities
d <- c(155, 195)
chisq.test(d, p = c(0.45, 0.55))
```


```{r}
# Test of independence
roboage <- rbind(c(65,30),c(100,25))
rownames(roboage) <- c("RoboOne", "RoboTwo")
colnames(roboage) <- c("0-45", "46-99")
roboage <- as.table(roboage)
roboage
chisq.test(roboage, correct=F)
```


```{r}
# McNemar's test
belief <- rbind(c(50,10),c(30,30))
rownames(belief) <- c("Belief", "Disbelief")
colnames(belief) <- c("Belief", "Disbelief")
belief <- as.table(belief)
belief
mcnemar.test(belief, correct=F)
```
