---output: pdf_document---
Alan T. Arnholt
4/10/15
The knitr package was designed to be a transparent engine for dynamic report generation with R, solve some long-standing problems in Sweave, and combine features in other add-on packages into one package.
library(PASWR2)
library(ggplot2)
ggplot(data = GRADES, aes(x = sat, y = gpa)) +
geom_point() + stat_smooth(method = "lm")
x = 'hello, python world!'
print(x)
print(x.split(' '))
fibs = (0, 1, 1, 2, 3) # tuple
print(fibs[3])
hello, python world!
['hello,', 'python', 'world!']
2
ggplot2library(dplyr)
EPI <- EPIDURALF %>%
mutate(BMI = kg/(cm/100)^2)
g1 <- ggplot(data = EPI, aes(x = BMI)) +
geom_density(fill = "pink") +
theme_bw() +
labs(x = expression(kg/m^2))
MD <- median(EPI$BMI)
SP <- IQR(EPI$BMI)
c(MD, SP)
[1] 30.827622 6.362825
The median BMI is 30.83 \( \text{kg}/\text{m}^2 \) and the BMI interquartile range is 6.36 \( \text{kg}/\text{m}^2 \).
ggplot(data = EPI, aes(x = BMI, fill = ease)) +
geom_density(alpha = 0.5) +
theme_bw()
levels(EPI$ease) <- c("Easy", "Difficult", "Impossible")
g2 <- ggplot(data = EPI, aes(x = treatment, fill = ease)) +
geom_bar(position = "fill", colour = "black") +
theme_bw() +
labs(x = "", y = "Fraction") +
guides(fill = guide_legend("Ease of\nPalpating\nPatient")) +
facet_grid(.~ doctor) +
theme(axis.text.x = element_text(angle = 75, hjust = 1.0))
g3 <- ggplot(data = EPI, aes(x = treatment, y = BMI, fill = treatment)) +
geom_boxplot() +
theme_bw() +
facet_grid(ease ~ doctor) +
theme(axis.text.x = element_text(angle = 75, hjust = 1.0)) +
guides(fill = FALSE) +
labs(x = "")
\[ \text{CI}_{1-\alpha}(\pi)=\left[p-z_{1-\alpha/2} \sqrt{\frac{p(1-p)}{n}},\: p+z_{1-\alpha/2} \sqrt{\frac{p(1-p)}{n}} \right] \]
\[ \text{CI}_{1-\alpha}(\pi)=\left[\tilde{p}-z_{1-\alpha/2} \sqrt{\frac{\tilde{p}(1-\tilde{p})}{\tilde{n}}},\: \tilde{p}+z_{1-\alpha/2} \sqrt{\frac{\tilde{p}(1-\tilde{p})}{\tilde{n}}} \right] \]
\[ \text{CI}_{1-\alpha}(\pi)=\left[\beta_{\alpha/2, x, n - x + 1}, \beta_{1 - \alpha/2, x + 1, n - x} \right] \]
\[ \text{CI}_{1-\alpha}(\pi) = \left[\dfrac{p+\frac{z^2_{1-\alpha/2}}{2n}-z_{1-\alpha/2}\sqrt{\frac{p(1-p)}{n}+\frac{z^2_{1-\alpha/2}}{4n^2}}}{\left(1+\frac{z^2_{1-\alpha/2}}{n} \right)}\right., \]
\[ \left. \dfrac{p+\frac{z^2_{1-\alpha/2}}{2n}+z_{1-\alpha/2}\sqrt{\frac{p(1-p)}{n}+\frac{z^2_{1-\alpha/2}}{4n^2}}}{\left(1+\frac{z^2_{1-\alpha/2}}{n} \right)} \right] \]
The coverage probability of a confidence interval procedure for estimating \( \pi \) at a fixed value of \( \pi \) is
\[ C_n(\pi)=\sum_{k=0}^{n}I(k,\pi)\binom{n}{k}\pi^k(1 - \pi)^{n-k} \]
where \( I(k,\pi) \) equals 1 if the interval contains \( \pi \) when \( X = k \) and equals 0 if it does not contain \( \pi \).
In other words, the coverage probability of a confidence interval is the proportion of all possible confidence intervals for a fixed \( \pi \) that contain \( \pi \).
ggplot2, package development, data wrangling (dplyr, tidyr), RMarkdown, and shiny