R Markdown Exercise: Multi-Sample Tests and Randomization Test
Please use this template (Right click and choose Save Link As...) for this RMarkdown exercise.
In this problem, you will analyze the Stat 100 survey 3 data in Fall 2015. The csv file can be downloaded here. The column variables are described on this webpage. The purpose of this exercise is to find out if there is any association between happiness (a person's subjective well-being) and a person's temperament (introvert/extrovert/ambirvert).
- (2 points) Create box plots of 'happiness' for the introverts, extroverts and ambiverts. Add the group means to the box plots.
- (3 points) Perform an F-test to determine if there are any significant differences on the reported scale of happiness among introverts, extroverts and ambiverts. Report the p-value and state your conclusion.
- (4 points) Perform pairwise t-tests with Bonferroni correction to adjust the p-values. Determine from the adjusted p-values which pairs of groups show significant differences at the 5% level.
- (5 points) Perform a randomization test by scrambling the 'happiness' variable and calculate the values of R2 of the scrambled data. Repeat the experiment at least 5000 times. Make a histogram of these R = √R2 and indicate the position of the original R (from the unscrambled data).
Note: The result of your randomization test must be reproducible. Therefore, you must set a seed number before calling any function involving random numbers. Useset.seed(your UIN)
to set the seed. You can simply follow the procedure in this week's notes. You are not required to optimize the code. - (3 points) Use the result of (d) to estimate the p-value. How does this estimated p-value compare to the one computed in part (b)?
Guidelines
- Write down your name in the R markdown file.
- Generate an html file from the markdown file by knitr.
- You should download the data file to your computer and then load it to R, instead of loading it directly from the website. This is for the purpose of reproducibility: the file at the remote website may be changed or disappear later and your R markdown file cannot be run. By saving it to your computer in the same location of the markdown file, you can be sure that your markdown result is reproducible.
- Show all codes and output. If your code chunk contains more than a few lines, include a brief explanation of what you are doing unless you write your code in a self-explanatory style.
- Label and state the answers to each question clearly. Don't just show the code and say that the information is in the output.
Solution
- RMarkdown file (Download the file and save it in the same folder as the data file you downloaded above. Open it with R Studio and then click "Knit".)
- Knitted html file