-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.R
34 lines (28 loc) · 1.15 KB
/
testing.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
n = 10000
reliability = .80
true.score = rnorm(n)
measure.1 = true.score * sqrt(reliability) + rnorm(n) * sqrt(1 - reliability)
measure.2 = true.score * sqrt(reliability) + rnorm(n) * sqrt(1 - reliability)
change = measure.2 - measure.1
d = data.frame(true.score,
measure.1,
measure.2,
change)
c = round(cor(d),3);c
c[4, 2]^2 + c[4, 3]^2 + c[1, 2]^2
text = str_c("Regression effect slope = ", -(1 - reliability))
grob = grobTree(textGrob(text, x = .95, y = 0.95, hjust = 1,
gp=gpar(col="red", fontsize=13)))
ggplot(d, aes(measure.1, change)) +
geom_point(alpha = .7) +
geom_smooth(method = lm, se = F) +
annotation_custom(grob) +
scale_x_continuous(breaks = seq(-10, 10, by = .5)) +
scale_y_continuous(breaks = seq(-10, 10, by = .5)) +
xlab("First measurement") + ylab("Change between first and second measurement")
ggplot(d, aes(measure.1, measure.2)) +
geom_point(alpha = .7) +
geom_smooth(method = lm, se = F) +
scale_x_continuous(breaks = seq(-10, 10, by = .5)) +
scale_y_continuous(breaks = seq(-10, 10, by = .5)) +
xlab("First measurement") + ylab("Second measurement")