This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.R
86 lines (50 loc) · 2.79 KB
/
global.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Reliability and Measurement Error #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# File contributors: #
# - M.A. Constantin #
# #
# File description: #
# - contains helper functions and variables used by the Shiny app #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Libraries.
# if (!('plotrix' %in% rownames(installed.packages()))) {
# install.packages('plotrix')
# }
library(shiny)
library(plotrix)
# # # Constants.
# Variables used in the graphical user interface.
..GRAPHICS.. <- list(
col.blue = rgb(0, 110, 255, maxColorValue = 255, alpha = 125, names = "blue"),
col.red = rgb(255, 100, 100, maxColorValue = 255, alpha = 125, names = "red")
)
# # # Helper functions.
# Normalize circle radius (i.e., to keep everything within the (x, y) range).
normalize <- function(x, min = 0, max = 100) {
return((x - min) / (max - min))
}
# Function for computing theoretical reliability (i.e., classical test theory).
true.reliability <- function(true.score = 100, mes.error = 50) {
return(true.score / (true.score + mes.error))
}
# Plot function.
app.plot <- function(ui.input) {
# # # Set margins.
par(mar = c(2, 2, 2, 2))
# Create axes for plot.
plot(x = seq(-2, 2, .1), y = seq(-2, 2, .1), type = "n", xlab = "", ylab = "", main = "Theoretical Reliability", bty = "n")
# Draw true score variance.
draw.circle(0, 0, normalize(ui.input$true.score.variance), col = ..GRAPHICS..$col.blue, border = ..GRAPHICS..$col.blue, lwd = 2)
# Draw measurement error variance.
draw.circle(0, 0, normalize(ui.input$measurement.error.variance), col = ..GRAPHICS..$col.red, border = ..GRAPHICS..$col.red, lwd = 2)
# Text for reliability.
reliability <- paste0("R = ", ui.input$true.score.variance, " / (", ui.input$true.score.variance, " + ", ui.input$measurement.error.variance, ") = ", round(true.reliability(ui.input$true.score.variance, ui.input$measurement.error.variance), 3))
# Add reliability text.
text(0, -1.9 , labels = reliability, cex = 1.5)
# Add legend.
legend(-2, 2, legend = c("True score variance", "Measurement error variance"), col = c(..GRAPHICS..$col.blue, ..GRAPHICS..$col.red), pch = 19, cex = 1.3)
}
# # # End.