-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.R
61 lines (43 loc) · 1.8 KB
/
server.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
#Interactive Exploration: The impact of outlier on regression results
#An R Shiny - d3.js application.
# Downward Bias the $R^2$:
#Consider the outlier on the left side. It does not fit the **line** the rest of the data points create.
#Click&Drag it on the right in the line with the other points and see what happens to the $R^2$.
# Upward Bias the $R^2$:
#Consider the outlier in the lower right hand corner. It does not fit the **circle** the rest of the data points create.
#Click&Drag it on the right in the line with the other points and see what happens to the $R^2$.
# Final Remarks
#Credits to unknown: I remember seeing a similar show case in the field of psychology some time ago. I think it was
#pure java-script implementation. Unfortunately, I could not find it again.
library(shiny)
options(digits = 2)
df <- data.frame(
x = seq(from = 20, to = 150, length.out = 10) + rnorm(10)*8,
y = seq(from = 20, to = 150, length.out = 10) + rnorm(10)*8
)
df$y[1] = df$y[1] + 80
shinyServer( function(input, output, session) {
output$mychart <- renderDragableChart({
df
}, r = 3, color = "purple")
output$regression <- renderPrint({
if (!is.null(input$JsData)) {
mat <- matrix(
data = as.integer(input$JsData),
ncol = 2,
byrow = TRUE
)
summary(
object = lm(formula = mat[, 2] ~ mat[, 1])
)
} else {
summary(
object = lm(df$y ~ df$x)
)
}
})
})
# Check out how your R-squared and the significance of your estimates can heavily depend
# upon a single data point.
# Note: The idea of the second chart was already published by somebody else. Unfortunately,
# I could not find the site anymore, so I decided it to reproduce it in d3 and R.