WISE R CLUB, Xiaojun Sun, 2014.07.11
This is the second assignment for WISE R Club members. You’d better read Chapter 5 to Chapter 8 of R in Action before trying to finish this assignment. The questions are described as following.
CONTENTS
Write a factorial function with the name Fac
by yourself. The function can realize the flowing features: $Fac(n)=1$ if $n=0$ and $Fac(n)=n(n-1)(n-2)…1$ for any integer $n>0$. Please not use the factorial()
function provided in R, try to write your own factorial function. Make the function as simple and short as possible.
Based on the dataset grades.txt
which I gave you in the last assignment, answer the following questions.
Draw the box plots of the test scores of the three courses: Math
, Chinese
and English
in one graph just like Figure 6.12 in the book.
Take sum of the test scores of the three courses(Math, Chinese and English), record it as variable Sum
. Grade each student from A+
to D
based on the 80th, 60th, 40th and 20th percentile of Sum
according to the table below. You may refer to Listing 5.6 in the book.
Grades | Condition |
---|---|
A+ | Sum >= the 80th percentile |
A | Sum < the 80th percentile, but >= the 60th percentile |
B | Sum < the 60th percentile, but >= the 40th percentile |
C | Sum < the 40th percentile, but >= the 20th percentile |
D | Sum < the 20th percentile |
Write a function named Grade
, whose input is the name of one student and output is the grade of him or her.
Draw a pie chart of the grades: A+
, A
, B
, C
and D
from table
with label for each part of the pie chart. You may refer to Listing 6.5 in the book.
Divide the students into five groups by the grades: A+
, A
, B
, C
and D
. Describe the mean and standard error of test scores for each group.
Based on the same dataset grades.txt
, answer the following questions.
Regress Math
on Chinese
and English
. Summarize the result and draw a diagnostic plot like Figure 8.6 in the book. See what conclusion you can draw from this plot.
Draw a histogram of the studentized residuals and superimposes a normal curve, kernel density curve and rug plot. You may refer to Listing 8.6 in the book, but not use that residplot
function unless you know how it works.
WISE R Club project is proudly maintained by XiaojunSun.