Created
June 5, 2012 05:42
-
-
Save jeromyanglim/2872909 to your computer and use it in GitHub Desktop.
Test of Rpubs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This document is just a test of RPubs platform for publishing R Markdown. I'll use the `survey` dataset from the `MASS` package to explore a few features. | |
```{r get_data, message=FALSE} | |
library(MASS) | |
library(psych) | |
library(Hmisc) | |
library(xtable) | |
data(survey) | |
``` | |
# Overview of the survey dataset | |
So let's have a look at this dataset | |
```{r} | |
head(survey) | |
``` | |
As you can see, it contains an assortment of measurements for `r nrow(survey)` individuals. | |
```{r describe_data} | |
Hmisc::describe(survey) | |
``` | |
# Are males taller? | |
```{r} | |
boxplot(Height ~ Sex, survey) | |
fit1 <- lm(Height ~ Sex, survey) | |
summary(fit1) | |
``` | |
Yes, as expected, males are taller. The expected difference is `r round(coef(fit1)['SexMale'], 1)` centimetres or `r round(coef(fit1)['SexMale'] / 2.54, 1) ` inches. | |
# Is smoking related to exercise? | |
```{r results='asis'} | |
survey$ExerSome <- survey$Exer %in% c("Freq", "Some") | |
tab1 <- table(smoke=survey$Smoke, exercise=survey$ExerSome) | |
print(xtable(tab1, caption='Cell counts'), 'html') | |
print(xtable(round(prop.table(tab1, 1), 2), caption='Proportion within smoker category'), 'html') | |
``` | |
```{r} | |
chisq.test(tab1) | |
``` | |
No, it doesn't look like it. | |
# What are the correlations between the different physical measurements? | |
```{r} | |
pairs.panels(survey[, c("Wr.Hnd", "NW.Hnd", "Height")]) | |
``` | |
This above figure shows the pearson correlation coefficient between writing hand span (`Wr.Hnd`), non-writing hand span (`NW.Hnd`) and actual height (`Height`). | |
# Conclusion | |
As I said at the start, this is just my first test of the RPub publishing platform for R Markdown. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment