Week 18- R Studio Flashcards

1
Q

how do you empty the r environment

A

rm(list=ls())

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

what is the code for a linear model?

A

model <- lm(mean.acc ~ HLVA, data = study.one)
summary(model)

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

how do you include a prediction line in your scatterplot?

A

ggplot(data = study.one, aes(x = HLVA, y = mean.acc)) +
geom_point(alpha = 0.5, size = 2,) +
geom_abline(intercept = 0.61399, slope = 0.02272, colour = “red”, size = 1.5) +
theme_bw() +
labs(x = “Health literacy (HLVA)”, y = “mean accuracy”) +
xlim(0, 16) + ylim(0, 1)
the geom_abline bit

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

How do you edit the appearance of marginal effect (prediction plot)

A

p.model <- plot(dat)
p.model +
geom_point(data = study.one,
aes(x = HLVA, y = mean.acc), size = 1.5, alpha = .75, colour = “lightgreen”) +
geom_line(size = 1.5) +
ylim(0, 1.1) + xlim(0, 16) +
theme_bw() +
theme(
axis.text = element_text(size = rel(1.15)),
axis.title = element_text(size = rel(1.25)),
plot.title = element_text(size = rel(1.4))
) +
xlab(“Health literacy (HLVA)”) + ylab(“Mean accuracy”) +
ggtitle(“Effect of health literacy on mean comprehension accuracy”)

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

what are the stages for editing the appearance of marginal effect?

A

– 1 – p.model <- plot(dat) – we create a plot object, which we call ‘p.model’

– 2 – p.model +
# – we then set up the first line of a series of lines, starting with the name of
# the plot, ‘p.model’ and a + to show we are going to add some edits

– 3 – geom_point(data = study.one, aes(x = HLVA, y = mean.acc) …)
# – we first add the raw data points showing the observed HLVA and mean.acc for
# each person in our sample

– 4 – geom_point(… size = 1.5, alpha = .75, colour = “lightgreen”) +
# – we modify the appearance of the points, then

– 5 – geom_line(size = 1.5) +
# – we add the prediction line, using the predictions created earlier, then

– 6 – ylim(0, 1.1) + xlim(0, 16) +
# – we set axis limits to show the full potential range of variation in each variable, then

– 7 – theme_bw() – we set the theme to black and white, then

– 8 – theme(axis.text = element_text(size = rel(1.15)),
# axis.title = element_text(size = rel(1.25)),
# plot.title = element_text(size = rel(1.4))
# )
# – we modify the relative size of x-axis, y-axis and plot title label font, then

– 9 – xlab(“Health literacy (HLVA)”) + ylab(“Mean accuracy”) +
# – we edit labels to make them easier to understand, then

– 10 – ggtitle(“Effect of health literacy on mean comprehension accuracy”)
# – we give the plot a title

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

How do you create a boxplot?

A

ggplot(data = study.one, aes(x = ETHNICITY, y = mean.acc)) +
geom_boxplot() +
theme_bw() +
labs(x = “Ethnicity, ONS categories”, y = “Mean accuracy of understanding (‘mean.acc’)”) +
ylim(0, 1.1)

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