-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completed class activity 2 (Timothy Lee) #3
Open
timothyLeeXQ
wants to merge
4
commits into
core-methods-in-edm:master
Choose a base branch
from
timothyLeeXQ:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,16 @@ D2 <- filter(D1, schoolyear == 20112012) | |
|
||
#Histograms | ||
```{r} | ||
#Generate a histogramof the percentage of free/reduced lunch students (frl_percent) at each school | ||
#Generate a histogram of the percentage of free/reduced lunch students (frl_percent) at each school | ||
|
||
hist() | ||
hist(D2$frl_percent) | ||
|
||
#Change the number of breaks to 100, do you get the same impression? | ||
|
||
hist(D2$frl_percent, breaks = 100) | ||
|
||
#Yes. Both histograms show negative skew with most data around 80% of students with free/reduced lunch. | ||
|
||
#Cut the y-axis off at 30 | ||
|
||
hist(D2$frl_percent, breaks = 100, ylim = c(0,30)) | ||
|
@@ -31,8 +33,6 @@ hist(D2$frl_percent, breaks = 100, ylim = c(0,30)) | |
|
||
hist(D2$frl_percent, breaks = c(0,10,20,80,100)) | ||
|
||
|
||
|
||
``` | ||
|
||
#Plots | ||
|
@@ -76,25 +76,33 @@ pairs(D5) | |
1. Create a simulated data set containing 100 students, each with a score from 1-100 representing performance in an educational game. The scores should tend to cluster around 75. Also, each student should be given a classification that reflects one of four interest groups: sport, music, nature, literature. | ||
|
||
```{r} | ||
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 20 | ||
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 15 | ||
#pmax sets a maximum value, pmin sets a minimum value | ||
#round rounds numbers to whole number values | ||
#sample draws a random samples from the groups vector according to a uniform distribution | ||
|
||
|
||
studentPerformance = rnorm(100, 75, 15) | ||
studentPerformance[studentPerformance > 100] = 100 | ||
studentPerformance[studentPerformance < 1] = 1 | ||
studentPerformance = round(studentPerformance) | ||
studentInterest = sample(c("sport", "music", "nature", "literature"), size = 100, replace = TRUE) | ||
studentData = data.frame(id = c(1:100), studentPerformance, studentInterest) | ||
``` | ||
|
||
2. Using base R commands, draw a histogram of the scores. Change the breaks in your histogram until you think they best represent your data. | ||
|
||
```{r} | ||
|
||
hist(studentData$studentPerformance, breaks = 8) | ||
``` | ||
|
||
|
||
3. Create a new variable that groups the scores according to the breaks in your histogram. | ||
|
||
```{r} | ||
#cut() divides the range of scores into intervals and codes the values in scores according to which interval they fall. We use a vector called `letters` as the labels, `letters` is a vector made up of the letters of the alphabet. | ||
letters = c("F", "E", "D", "C", "B", "A") | ||
studentGrade = cut(studentData$studentPerformance, | ||
breaks = c(40, 50, 60, 70, 80, 90, 100), | ||
labels = letters) | ||
studentData = cbind(studentData, studentGrade) | ||
|
||
``` | ||
|
||
|
@@ -106,47 +114,55 @@ library(RColorBrewer) | |
|
||
#The top section of palettes are sequential, the middle section are qualitative, and the lower section are diverging. | ||
#Make RColorBrewer palette available to R and assign to your bins | ||
histColourPalette = brewer.pal(7, "OrRd") | ||
|
||
#Use named palette in histogram | ||
|
||
hist(studentData$studentPerformance, breaks = 8, col = histColourPalette) | ||
``` | ||
|
||
|
||
5. Create a boxplot that visualizes the scores for each interest group and color each interest group a different color. | ||
|
||
```{r} | ||
#Make a vector of the colors from RColorBrewer | ||
|
||
boxColourPalette = brewer.pal(4, "Spectral") | ||
boxplot(studentData$studentPerformance ~ studentData$studentInterest, col = boxColourPalette) | ||
``` | ||
|
||
|
||
6. Now simulate a new variable that describes the number of logins that students made to the educational game. They should vary from 1-25. | ||
|
||
```{r} | ||
|
||
logins = sample(c(1:25), size = 100, replace = TRUE) | ||
studentData = cbind(studentData, logins) | ||
``` | ||
|
||
7. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group. | ||
|
||
```{r} | ||
|
||
plot(studentData$studentPerformance, studentData$logins, | ||
main = "Plot of Logins against scores", | ||
xlab = "Student Scores", | ||
ylab = "Student Logins", | ||
col = studentData$studentInterest, | ||
pch=19) | ||
|
||
``` | ||
|
||
|
||
8. R contains several inbuilt data sets, one of these in called AirPassengers. Plot a line graph of the the airline passengers over time using this data set. | ||
|
||
```{r} | ||
|
||
plot(AirPassengers, type = "l") | ||
``` | ||
|
||
|
||
9. Using another inbuilt data set, iris, plot the relationships between all of the variables in the data set. Which of these relationships is it appropraiet to run a correlation on? | ||
|
||
```{r} | ||
|
||
pairs(iris) | ||
``` | ||
|
||
10. Finally use the knitr function to generate an html document from your work. If you have time, try to change some of the output using different commands from the RMarkdown cheat sheet. | ||
|
||
*I presume this just means press "knit"?* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way: |
||
|
||
11. Commit, Push and Pull Request your work back to the main branch of the repository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job overall! |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an another way of setting maximum and minimum values with a single line of code.
round(pmax(1, pmin(100, rnorm(n=100, mean=75, sd=15))))