Last active
October 28, 2019 19:32
-
-
Save JosiahParry/631fae657f5662f14132143953861d72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# set argument values by name | |
d <- rnorm(302, mean = 43.3, sd = 9.1) | |
# set them by position | |
i <- rnorm(212, 44.6, 9.2) | |
r <- rnorm(278, 45.1, 9.2) | |
# note that you do not need to put these functions inside of the c() function | |
# because they are already returning vectors. | |
# we use c now because we want to combine multiple vectors into one | |
dri <- c(d, i, r) | |
# now we need to create a second vector that indicates which party these are from | |
# we know that the first 302 are Dems because we created 302 random values | |
# 212 and 278 for I and R | |
# this means we need to create a vector where the first 302 vals are D, then 212 I, 278 R | |
# we can use the function rep() -- repeat -- to repeat values a number of times | |
party <- c(rep("d", 302), rep("i", 212), rep("r", 278)) | |
# we can combine these two vectors into a single data frame | |
# we are creating a dataframe called df, creative, i know, with a column called | |
# age which is the dri vector and another col called party which is the party vector | |
df <- data.frame( | |
age = dri, | |
party = party | |
) | |
# now we can do the anova | |
# what this says is that i want to look at the variance of age grouped by party | |
# and we want to use the dataframe called df | |
party_aov <- aov(age ~ party, data = df) | |
# now we can look at the summary of all of this | |
summary(party_aov) | |
# we see that there is a statistically signficant difference by party (p < .05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment