Week 16- R studio Flashcards

1
Q

What is the as.factor function and how do you use it?

A

When you want to convert the data type of a variable to a factor/categorical variable.

studytwo$ETHNICITY <- as.factor(studytwo$ETHNICITY)
summary(studytwo)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to see an overview of the data

A

head(studytwo)
summary(studytwo)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you do a histogram (using a ggplot)

A

ggplot(data = studytwo, aes(x = mean.acc)) + geom_histogram()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a binwidth and how do you add it onto a calculation?

A

We adjust binwidth typically to improve the appearance of the plot.
ggplot(data = studytwo, aes(x = SHIPLEY)) + geom_histogram(binwidth = 0.1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to edit the colour of histogram theme?

A

ggplot(data = studytwo, aes(x = SHIPLEY)) +
geom_histogram(binwidth = 0.5) +
theme_bw()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to edit the labels of the histogram

A

ggplot(data = studytwo, aes(x = SHIPLEY)) +
geom_histogram(binwidth = 0.5) +
theme_bw() +
labs(x = “SHIPLEY”, y = “number of”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create a scatterplot examining the association between variables?

A

ggplot(data = studytwo, aes(x = SHIPLEY, y = HLVA)) +
geom_point()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to change the appearance of a ggplot- alpha, size, colour, theme, labels

A

ggplot(data = studytwo, aes(x = HLVA, y = mean.self)) +
geom_point(alpha = 0.5, size = 2, colour = purple) +
theme_bw() +
labs(x = “HLVA”, y = “mean self rated accuracy”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you code a correlation test?

A

cor.test(studytwo$HLVA, studytwo$mean.acc, method = “pearson”, alternative = “two.sided”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly