Skip to content

Commit 731e1a5

Browse files
authored
Merge pull request #132 from ScPoEcon/fo/shinys
Fo/shinys
2 parents 75e5877 + 773a277 commit 731e1a5

File tree

32 files changed

+390
-168
lines changed

32 files changed

+390
-168
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: ScPoEconometrics
22
Type: Package
33
Title: ScPoEconometrics
4-
Date: 2018-11-15
5-
Version: 0.2.2
4+
Date: 2019-09-02
5+
Version: 0.2.3
66
Authors@R: c(
77
person("Florian", "Oswald", email = "[email protected]", role = c("aut","cre")),
88
person("Jean-Marc", "Robin", email = "[email protected]", role = "ctb"),
@@ -30,4 +30,4 @@ Imports: bookdown,
3030
Suggests:
3131
shinytest,
3232
testthat
33-
RoxygenNote: 6.1.0
33+
RoxygenNote: 6.1.1

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ export(launchApp)
55
export(runTutorial)
66
import(Ecdat)
77
import(EnvStats)
8+
import(Hmisc)
89
import(bookdown)
910
import(datasauRus)
1011
import(learnr)
12+
import(magick)
1113
import(mvtnorm)
14+
import(pdftools)
1215
import(plotly)
1316
import(reshape2)
1417
import(rmarkdown)

R/ScPoEconometrics-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
#' @import magick
3030
#' @import pdftools
3131
#' @import Hmisc
32+
#' @importFrom stats rnorm runif
3233
#' @keywords internal
3334
NULL

R/runexample.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11

2+
get_lm <- function(a,b,n=20,xscale = 1, escale = 1, seed = 1){
3+
set.seed(seed)
4+
x = runif(n,min = -1*xscale, max = xscale)
5+
y <- a + b * x + rnorm(n,sd = escale)
6+
list(x=x,y=y, a = a, b = b, n = n, xscale = xscale, escale = escale)
7+
}
8+
9+
10+
211
#' runTutorial: Run a Tutorial!
312
#'
413
#' @param tutoname string of which tutorial you want to run

inst/shinys/Rescale/app.R

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
library(shiny)
22

3+
rd = 1 # digits to round
4+
5+
set.seed(19)
6+
n = 20
7+
sigma = 5
8+
9+
x <- rnorm(n, 2, 1)
10+
a_true = 10
11+
b_true = 3
12+
y <- a_true + b_true*x + rnorm(n, 0, sigma)
13+
314
ui <- fluidPage(
415
br(),
516
br(),
6-
sidebarPanel(sliderInput("scale_x", "Rescale X", min = -5,
7-
max = 5, step = .5, value = 1),
8-
sliderInput("scale_y", "Rescale Y", min = -5,
9-
max = 5, step = .5, value = 1),
17+
sidebarPanel(sliderInput("scale_x", "Rescale X", min = -2,
18+
max = 2, step = .5, value = 1),
19+
sliderInput("scale_y", "Rescale Y", min = -0.5,
20+
max = 2, step = .5, value = 1),
1021
br(),
1122
br(),
1223

@@ -21,20 +32,11 @@ ui <- fluidPage(
2132
server <- function(input,output){
2233
output$best_fit <- renderText({
2334

24-
rd = 1 # digits to round
25-
26-
set.seed(19)
27-
n = 10000
28-
sigma = 5
29-
30-
x <- rnorm(n, 2, 40)
31-
y <- 10 + 3*x + rnorm(n, 0, sigma)
32-
3335
s_x <- input$scale_x
3436
s_y <- input$scale_y
3537

36-
orig_slope <- (cov(x, y)/var(x))
37-
orig_inter <- mean(y) - orig_slope*mean(x)
38+
orig_slope <- b_true
39+
orig_inter <- a_true
3840

3941
best_slope <- (s_y/s_x) * orig_slope #scale
4042
best_inter <- s_y * orig_inter
@@ -55,23 +57,15 @@ server <- function(input,output){
5557

5658
output$regPlot_rescale <- renderPlot({
5759

58-
set.seed(19)
59-
n = 100
60-
sigma = 5
61-
62-
x <- rnorm(n, 2, 10)
63-
y <- 10 + 3*x + rnorm(n, 0, sigma)
64-
6560
s_x <- input$scale_x
6661
s_y <- input$scale_y
6762

6863
fit <- lm(y ~ x, data.frame(x = (s_x*x), y = (s_y*y)))
6964

70-
7165
plot((s_x*x), (s_y*y), type = "p", pch = 21, col = "blue", bg = "royalblue",
72-
xlim = c(-50, 50),
66+
xlim = c(-5, 10),
7367
xlab = paste0(s_x, "X"),
74-
ylim = c(-200, 300),
68+
ylim = c(-10, 45),
7569
ylab = paste0(s_y, "Y"),
7670
main = "Rescale X and Y", frame.plot = FALSE,
7771
cex = 1.)
@@ -82,8 +76,7 @@ server <- function(input,output){
8276
})
8377

8478
output$DGP <- renderText({
85-
n = 100
86-
paste0("Data Generating Process: Y = 10 + 3X + error\nSample Size N = ",n)
79+
paste0("Data Generating Process: Y = 10 + 3X + error")
8780
})
8881

8982
}

inst/shinys/Rescale/tests/mytest-expected/001.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"input": {
3-
"scale_x": 0.5,
4-
"scale_y": -3.5
3+
"scale_x": 1,
4+
"scale_y": 1
55
},
66
"output": {
7-
"best_fit": "Original Slope: 3\nOriginal Intercept: 10\nCurrent Slope: -21\nCurrent Intercept: -35",
8-
"DGP": "Data Generating Process: Y = 10 + 3X + error\nSample Size N = 100",
7+
"best_fit": "Original Slope: 3\nOriginal Intercept: 10\nCurrent Slope: 3\nCurrent Intercept: 10",
8+
"DGP": "Data Generating Process: Y = 10 + 3X + error",
99
"regPlot_rescale": {
10-
"src": "[image data sha1: 1d069b300188fa630f19f995dbe8a25e6901efa0]",
10+
"src": "[image data sha1: 58fe26b729baf45fb259a0797a43bcc9db8078a8]",
1111
"width": 611,
1212
"height": 400,
1313
"coordmap": {
1414
"panels": [
1515
{
1616
"domain": {
17-
"left": -54,
18-
"right": 54,
19-
"bottom": -220,
20-
"top": 320
17+
"left": -5.6,
18+
"right": 10.6,
19+
"bottom": -12.2,
20+
"top": 47.2
2121
},
2222
"range": {
2323
"left": 59.04,
-7.82 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"input": {
3+
"scale_x": 1,
4+
"scale_y": 1
5+
},
6+
"output": {
7+
"best_fit": "Original Slope: 3\nOriginal Intercept: 10\nCurrent Slope: 3\nCurrent Intercept: 10",
8+
"DGP": "Data Generating Process: Y = 10 + 3X + error",
9+
"regPlot_rescale": {
10+
"src": "[image data sha1: 58fe26b729baf45fb259a0797a43bcc9db8078a8]",
11+
"width": 611,
12+
"height": 400,
13+
"coordmap": {
14+
"panels": [
15+
{
16+
"domain": {
17+
"left": -5.6,
18+
"right": 10.6,
19+
"bottom": -12.2,
20+
"top": 47.2
21+
},
22+
"range": {
23+
"left": 59.04,
24+
"right": 580.76,
25+
"bottom": 325.56,
26+
"top": 58.04
27+
},
28+
"log": {
29+
"x": null,
30+
"y": null
31+
},
32+
"mapping": {
33+
34+
}
35+
}
36+
],
37+
"dims": {
38+
"width": 611,
39+
"height": 400
40+
}
41+
}
42+
}
43+
},
44+
"export": {
45+
46+
}
47+
}
45.5 KB
Loading

inst/shinys/Rescale/tests/mytest.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
app <- ShinyDriver$new("../")
22
app$snapshotInit("mytest")
33

4-
app$setInputs(scale_x = -1.5)
5-
app$setInputs(scale_x = 2)
4+
app$snapshot()
5+
app$setInputs(scale_y = 1.5)
6+
app$setInputs(scale_y = 2)
67
app$setInputs(scale_y = 0)
7-
app$setInputs(scale_y = 3)
8-
app$setInputs(scale_y = 4)
8+
app$setInputs(scale_y = -0.5)
9+
app$setInputs(scale_y = 1)
910
app$setInputs(scale_x = 1.5)
11+
app$setInputs(scale_x = 2)
12+
app$setInputs(scale_x = -1)
13+
app$setInputs(scale_x = -1.5)
14+
app$setInputs(scale_x = -2)
1015
app$setInputs(scale_x = 0.5)
11-
app$setInputs(scale_y = -3.5)
16+
app$setInputs(scale_x = 1)
1217
app$snapshot()

0 commit comments

Comments
 (0)