diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..f70b1cf --- /dev/null +++ b/.lintr @@ -0,0 +1 @@ +linters: with_defaults(line_length_linter(120), camel_case_linter = NULL, snake_case_linter) diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..9cfb979 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,26 @@ +Title: Regression Lines +ShortName: Regression Lines +Date: 2019-01-08 +Lifecycle: experimental +Authors@R: c( + person(given = "Caihui", family = "Xiao", role = c("aut", "cre")), + person(given = "Zhiliang", family = "Zhang", role = c("ctb")), + person(given = "Jiajun", family = "Gao", role = c("ctb")), + person(given = "Daehoon", family = "Gwak", role = c("ctb")), + person(given = "Sitong", family = "Liu", role = c("ctb")), + person(given = "Sean", family = "Burke", role = c("ctb")), + person(given = "Dennis", family = "Pearl", role = c("aut")), + person(given = "Neil", family = "Hatfield", role = c("aut")), + person(given = "Nathan", family = "Pechulis", role = c("ctb")) + ) +Chapter: Data Description +Description: This app provides an opportunity to explore how the correlation and regression line relate to the points on a scatterplot. +LearningObjectives: c( + "The student will learn to understand how the correlation and regression line are related to the points displayed in a scatterplot." + ) +DisplayMode: Normal +URL: https://psu-eberly.shinyapps.io/Regression_Lines +BugReports: https://github.com/EducationShinyAppTeam/Regression_Lines/issues +License: CC-BY-NC-SA-4.0 +Tags: Game +Type: Shiny diff --git a/README.md b/README.md deleted file mode 100644 index 0a66f64..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Regression Lines - -[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/) ![experimental](https://img.shields.io/badge/lifecycle-experimental-orange) ![year](https://img.shields.io/badge/year-2017-lightgrey) - -![App Screenshot](https://sites.psu.edu/shinyapps/files/2018/11/6e98ed050f2295a0b58f4f6d3058b34c36c311dc-regressionline-2kw3ktt.png) - -In this app, you will explore the relationship between the regression line and points in a scatterplot. diff --git a/ToDoList.txt b/ToDoList.txt new file mode 100644 index 0000000..6630c1b --- /dev/null +++ b/ToDoList.txt @@ -0,0 +1,6 @@ +# Things Needed for This Version +1. + +# Ideas for Future Development + +1. Need to move away from hard coding questions and feedback to a question bank \ No newline at end of file diff --git a/app.R b/app.R new file mode 100644 index 0000000..9b3612e --- /dev/null +++ b/app.R @@ -0,0 +1,803 @@ +# Load Libraries +library(shinydashboard) +library(shiny) +library(shinyBS) +library(shinyWidgets) +library(boastUtils) +library(ggplot2) + +# Define global constants and functions ---- +## none at this time + +# Define the UI ---- +ui <- list( + ## app page ---- + dashboardPage( + skin = "yellow", + dashboardHeader( + titleWidth = 250, + title = "Regression Lines", + tags$li(class = "dropdown", actionLink("info", icon("info"))), + tags$li( + class = "dropdown", + boastUtils::surveyLink(name = "Regression_lines") + ), + tags$li( + class = "dropdown", + tags$a( + id = "home", + href = 'https://shinyapps.science.psu.edu/', + icon("house") + ) + ) + ), + ## Sidebar ---- + dashboardSidebar( + width = 250, + sidebarMenu( + id = "pages", + menuItem("Overview", tabName = "overview", icon = icon("gauge-high")), + menuItem("Prerequisites", tabName = "prerequisites", icon = icon("book")), + menuItem("Challenge", tabName = "challenge", icon = icon("gears")), + menuItem("References", tabName = "References", icon = icon("leanpub")) + ), + tags$div( + class = "sidebar-logo", + boastUtils::sidebarFooter() + ) + ), + ## Body ---- + dashboardBody( + tabItems( + ### Overview ---- + tabItem( + tabName = "overview", + h1("Regression Lines"), + p( + "In this app, you will explore how correlation and + regression lines relate to the points on a scatterplot." + ), + br(), + h2("Instructions"), + tags$ol( + tags$li( + "Head to the 'Prerequisites' page to review concepts related to + correlation and regression lines." + ), + tags$li( + "When ready, make your way to the 'Challenge' page to further explore + these concepts." + ), + tags$li( + "There, you can create points by clicking on the scatterplot and create + your own line by adjusting the sliders for slope and intercept." + ), + tags$li("Use these interactive elements to mimic the situation that + is presented to complete the challenges.") + ), + br(), + div( + style = "text-align: center;", + bsButton( + inputId = "goToPrereq", + label = "Prerequisites", + icon = icon("book"), + size = "large", + ) + ), + #Acknowledgements + br(), + br(), + h2("Acknowledgements"), + p( + "This app was developed and coded by Caihui Xiao. + The app was further updated by Zhiliang Zhang and Jiajun Gao + in June 2018, Daehoon Gwak in July 2020, Sean Burke in June + 2023, and by Nathan Pechulis in July 2024.", + br(), + br(), + br(), + "Cite this app as:", + br(), + citeApp(), + br(), + br(), + div(class = "updated", "Last Update: 7/8/2024 by NP.") + ) + ), + ### Prerequisites ---- + tabItem( + withMathJax(), + tabName = "prerequisites", + h2("Prerequisites"), + p("To get the most out of this app, review the following information + about correlation and regression lines."), + br(), + box( + title = tags$strong("Correlation"), + tags$ul( + tags$li( + "Correlation measures the strength of the linear association + between two variables/attributes and is therefore not appropriate + for non-linear relationships. Correlations are always values + between –1 and +1, inclusive. A correlation of –1 or +1 indicates + that we have a perfect linear relationship; every point lies on + the regression line. Correlation is strongly affected by outliers." + ), + tags$li( + "Correlation does not change when you change the unit of + measurement. For instance, if you find the correlation between + elementary school children's height (in inches) and their ages + (years), that value will be the same if you convert everyone's + height to centimeters and/or their ages to days. More generally, + if you transform every observation's values by adding, + subtracting, multiplying, and/or dividing by the same number, + the correlation will remain the same." + ) + ), + collapsible = TRUE, + collapsed = TRUE, + width = 12 + ), + box( + title = tags$strong("Regression Lines"), + tags$ul( + tags$li( + "A regression line is the graph of a linear function thought to + describe how a response variable (typically \\(Y\\)) changes as + an explanatory variable (typically \\(X\\)) changes. The regression + line's linear form focuses on the", tags$em("predicted value"), + "of the response (\\(\\widehat{Y}\\)). Thus, when you know that + \\(X\\) takes on a specific value, \\(x\\), you can find the + predicted value with the formula: \\[\\widehat{Y}=a+b*x\\]" + ), + tags$li( + "In the above formula, \\(a\\) is an intercept--what you would + predict for \\(Y\\) when \\(x = 0\\). The \\(b\\) is the slope or + rate of change of \\(Y\\) with respect to \\(X\\). The slope tells + you how many times the change in \\(Y\\) is as large as the + corresponding change in \\(X\\). The sign of the slope will always + match the sign of the correlation value." + ), + tags$li( + "The regression line is the graph of the linear function that + minimizes the vertical distance between the line and each of the + cases (data points). This results in the smallest standard deviation + for the error (i.e., the vertical distance between the line and + each case). Recall that standard deviation measures variability + and we want to keep the variability around the line as small as + possible." + ), + tags$li( + "The regression line is not appropriate for making predictions + when", + tags$ul( + tags$li("there is a non-linear relationship,"), + tags$li("when there are outliers driving the prediction and/or + relationship, or"), + tags$li("when you are predicting far beyond the range of the + data.") + ) + ) + ), + collapsible = TRUE, + collapsed = TRUE, + width = 12 + ), + br(), + br() + ), + ### Challenge ---- + tabItem( + tabName = "challenge", + h2("Regression Line and Correlation on a Scatterplot"), + p( + "Use the interactive graph below to mimic the challenge that is being + proposed. To begin, create points by simply clicking on the graph and + adjust the values for your line's slope/intercept (if a line is needed) + while also checking the 'Create your own line' box. Then, you can + utilize the given feedback from the other two checkboxes to get as + close to the prompt as you can. Try your best to complete as many of + the challenges as you can; good luck!" + ), + br(), + h3("Challenge"), + uiOutput( + outputId = "question", + class = "largerFont" + ), + br(), + fluidRow( + column( + width = 4, + wellPanel( + sliderInput( + inputId = "intercept", + label = "Choose the intercept", + min = -10, + max = 10, + value = 5, + step = 0.01 + ), + sliderInput( + inputId = "slope", + label = "Choose the slope", + min = -10, + max = 10, + value = 2, + step = 0.01 + ), + checkboxInput( + inputId = "userLine", + label = "Create your own line (red)", + value = FALSE + ), + checkboxInput( + inputId = "regressionLine", + label = "Show regression line (blue)", + value = FALSE + ), + checkboxInput( + inputId = "correlation", + label = "Show correlation value", + value = FALSE + ), + bsButton( + inputId = "newChallenge", + label = "New Challenge", + icon = icon("forward"), + size = "large" + ), + bsButton( + inputId = "undoButton", + label = "Undo Point", + icon = icon("undo"), + size = "large", + disabled = TRUE + ), + bsButton( + inputId = "reset", + label = "Reset", + icon = icon("eraser"), + size = "large" + ) + ) + ), + column( + width = 8, + plotOutput( + outputId = "scatterPlot", + click = "clicks" + ), + br(), + h4("Feedback"), + textOutput('feedback'), + textOutput('userFunction'), + textOutput('regEqn'), + textOutput('correlation') + ) + ) + ), + ### References ---- + tabItem( + tabName = "References", + h2("References"), + p( #shinyBS + class = "hangingindent", + "Bailey, E. (2022). shinyBS: Twitter bootstrap components for shiny. + (v 0.61.1). [R package]. Available from + https://CRAN.R-project.org/package=shinyBS" + ), + p( #Boast Utilities + class = "hangingindent", + "Carey, R. and Hatfield, N. J. (2024). boastUtils: BOAST utlities. + (v 0.1.12.2). [R package]. Available from + https://github.com/EducationShinyAppTeam/boastUtils" + ), + p( #shinydashboard + class = "hangingindent", + "Chang, W., and Borges Ribeiro, B. (2021). shinydashboard: Create + dashboards with 'shiny'. (v 0.7.2) [R package]. Available from + https://CRAN.R-project.org/package=shinydashboard" + ), + p( #shiny + class = "hangingindent", + "Chang, W., Cheng J., Allaire, J., Sievert, C., Schloerke, B., Xie, Y., + Allen, J., McPherson, J., Dipert, A., and Borges, B. (2024). shiny: + Web application framework for R. (v 1.8.1.1). [R package]. Available + from https://CRAN.R-project.org/package=shiny" + ), + p( #shinyWidgets + class = "hangingindent", + "Perrier, V., Meyer, F., and Granjon, D. (2024). shinyWidgets: Custom + inputs widgets for shiny. (v 0.8.6). [R package]. Available from + https://CRAN.R-project.org/package=shinyWidgets" + ), + p( #reference for ideas + class = "hangingindent", + "Statistical Applets: Correlation and regression. (n.d.). [Web applet; + original idea]. Available from + http://digitalfirst.bfwpub.com/stats_applet/generic_stats_applet_5_correg.html" + ), + p( # ggplot2 + class = "hangingindent", + "Wickham, H. (2016). ggplot2: Elegant graphics for data analysis. + Springer-Verlag:New York. (v 3.5.1) [R package]. Available from + https://ggplot2.tidyverse.org" + ), + br(), + br(), + br(), + boastUtils::copyrightInfo() + ) + ) + ) + ) +) + +# Define the Server ---- +server <- function(input, output,session) { + ## Info Button ---- + observeEvent( + eventExpr = input$info, + handlerExpr = { + sendSweetAlert( + session = session, + title = "Information", + type = "info", + text = "This app will allow you to explore the connection between the data + points, their correlation, and the regression line through challenges + using an interactive scatterplot." + ) + } + ) + + ## Create Reactive Values ---- + userData <- reactiveVal(NULL) + challengeId <- reactiveVal(sample(x = 1:11, size = 1)) + + ## Prerequisites button ---- + observeEvent( + eventExpr = input$goToPrereq, + handlerExpr = { + updateTabItems( + session = session, + inputId = "pages", + selected = "prerequisites" + ) + } + ) + + ## New Challenge button ---- + observeEvent( + eventExpr = input$newChallenge, + handlerExpr = { + ### Reset values + userData(NULL) + challengeId(sample(x = 1:11, size = 1)) + + ### Update inputs + updateSliderInput( + session = session, + inputId = "slope", + value = 0 + ) + updateSliderInput( + session = session, + inputId = "intercept", + value = 0 + ) + updateCheckboxInput( + session = session, + inputId = "userLine", + value = FALSE + ) + updateCheckboxInput( + session = session, + inputId = "correlation", + value = FALSE + ) + updateCheckboxInput( + session = session, + inputId = "regressionLine", + value = FALSE + ) + } + ) + + ## Reset Button ---- + observeEvent( + eventExpr = input$reset, + handlerExpr = { + ### Reset values + userData(NULL) + + #Update inputs + updateSliderInput( + session = session, + inputId = "slope", + value = 0 + ) + updateSliderInput( + session = session, + inputId = "intercept", + value = 0 + ) + updateCheckboxInput( + session = session, + inputId = "userLine", + value = FALSE + ) + updateCheckboxInput( + session = session, + inputId = "correlation", + value = FALSE + ) + updateCheckboxInput( + session = session, + inputId = "regressionLine", + value = FALSE + ) + } + ) + + ## Generate and Display Questions ---- + observeEvent( + eventExpr = challengeId(), + handlerExpr = { + output$question <- renderText( + expr = { + switch( + EXPR = challengeId(), # integer selecting element + "Draw some points on a scatterplot that have y = 3 – 2x as their + regression and a correlation more than - 0.8. (Check the “Regression + line” box to see how you did.)", + "Draw some points on a scatterplot that have y = 2 + 3x as their + regression and a correlation less than 0.5. (Check the “Regression + line” box to see how you did.)", + "Draw some points on a scatterplot that have y = 2x + 1 as their + regression. (Check the “Show regression” box to see how you did.)", + "Draw your own line with the equation y = 3 – 2x and then add some + points that have that as their regression. (Check the “Show + regression” box to see how you did.)", + "Draw your own line with the equation y = 2 + 3x and then add some + points that have that as their regression. (Check the “Show + regression” box to see how you did.)", + "Create some points with a correlation of 0.6 and then draw your own + line that is your guess at the regression line. (Check the “Show + regression” box to see how you did.)", + "Create some points with a correlation of -0.5 and then draw your + own line that is your guess at the regression line. (Check the “Show + regression” box to see how you did.)", + "Create some points with a correlation of -0.2 and then draw your own + line that is your guess at the regression line. (Check the “Show + regression” box to see how you did.)", + "Create some points that have a strong non-linear relationship, but + a correlation between -0.1 and 0.1.", + "Create some points that have a strong non-linear relationship, but + a correlation between 0.4 and 0.6.", + "Create some points that follow a roughly linear pattern and a + correlation of 0.5 and then add an outlier to make the correlation + go down to 0." + ) + } + ) + } + ) + + ## Listen for clicks ---- + observeEvent( + eventExpr = input$clicks, + handlerExpr = { + if (is.null(userData())) { + userData(data.frame(x = input$clicks$x, y = input$clicks$y)) + } else if (nrow(userData()) < 1) { + userData(data.frame(x = input$clicks$x, y = input$clicks$y)) + } else { + userData(rbind(userData(), c(input$clicks$x, input$clicks$y))) + } + } + ) + ## Enable/Disable Undo ---- + observeEvent( + eventExpr = userData(), + handlerExpr = { + if (is.null(userData())) { + updateButton( + session = session, + inputId = "undoButton", + disabled = TRUE + ) + } else if (nrow(userData()) == 0) { + ## separate null case from zero row case to prevent app from crashing + updateButton( + session = session, + inputId = "undoButton", + disabled = TRUE + ) + } else { + updateButton( + session = session, + inputId = "undoButton", + disabled = FALSE + ) + } + }, + ignoreNULL = FALSE, + ignoreInit = TRUE + ) + + ## Undo Last Point Button ---- + observeEvent( + eventExpr = input$undoButton, + handlerExpr = { + # Remove the last row from the dataframe + userData(userData()[-nrow(userData()),]) + } + ) + + ## Render Scatter Plot ---- + observeEvent( + eventExpr = c(userData(), input$userLine, input$intercept, input$slope, + input$regressionLine), + handlerExpr = { + ### Capture Data ---- + if (is.null(userData())) { + plotData <- data.frame(x = numeric(), y = numeric()) + } else if (nrow(userData()) < 1) { + plotData <- data.frame(x = numeric(), y = numeric()) + } else { + plotData <- userData() + } + + ### Generate base plot ---- + basePlot <- ggplot( + data = plotData, + mapping = aes(x = x, y = y) + ) + + geom_point( + size = 4.5, + color = boastPalette[1] + ) + + scale_x_continuous( + breaks = seq(-5, 5, 2), + limits = c(-5,5), + expand = expansion(mult = 0, add = 0) + ) + + scale_y_continuous( + breaks = seq(-5, 5, 2), + limits = c(-5,5), + expand = expansion(mult = 0, add = 0) + ) + + labs(x = "X", y = "Y") + + theme_bw(base_size = 20) + + ### Add user's line ---- + if (input$userLine) { + basePlot <- basePlot + + geom_abline( + intercept = input$intercept, + slope = input$slope, + col = boastUtils::psuPalette[2], + lwd = 1.25 + ) + } + + ### Add regression line ---- + if (input$regressionLine) { + basePlot <- basePlot + + geom_smooth( + method = "lm", + formula = y ~ x, + se = FALSE, + fullrange = TRUE, + color = boastPalette[5], + linewidth = 1.25, + na.rm = TRUE + ) + } + + ### Build Alt text ---- + + if (is.null(userData())) { + altText <- "An empty plot going from -5 to 5 in both dimensions." + } else if (nrow(userData()) < 1) { + altText <- "An empty plot going from -5 to 5 in both dimensions." + } else if (nrow(userData()) < 3) { + altText <- paste0("A scatter plot showing ", nrow(userData()), " points") + } else { + sampleCor <- round(cor(userData())["x", "y"], digits = 2) + trendMsg <- ifelse( + test = sampleCor >= -0.1 && sampleCor <= 0.1, + yes = "no meaningful trend.", + no = ifelse( + test = sampleCor > 0.1, + yes = "a positive trend.", + no = "a negative trend." + ) + ) + altText <- paste0("A scatter plot showing ", nrow(userData()), + " points and ", trendMsg) + } + + if (input$userLine) { + altText <- paste(altText, "The user specified line also appears.") + } + + if (input$regressionLine) { + altText <- paste(altText, "The regression line also appears.") + } + + output$scatterPlot <- renderPlot( + expr = basePlot, + alt = altText + ) + } + ) + + ## Display feedback messages ---- + ### User's Linear Function ---- + observeEvent( + eventExpr = c(input$userLine, input$intercept, input$slope), + handlerExpr = { + if (!input$userLine) { + message <- NULL + } else { + message <- paste( + "Equation of your line: y =", + input$intercept, + "+ (", + input$slope, + ") * x" + ) + } + + output$userFunction <- renderText(expr = message) + } + ) + + ### Regression Equation ---- + observeEvent( + eventExpr = c(input$regressionLine, userData()), + handlerExpr = { + if (!input$regressionLine) { + message <- NULL + } else if (is.null(userData())) { + message <- "You must plot points first." + } else if (nrow(userData()) <= 1) { + message <- "More points are needed for a regression line." + } else { + model1 <- lm(formula = y ~ x, data = userData()) + + message <- paste( + "Regression Equataion: y =", + round(coef(model1)[1], digits = 2), + "+ (", + round(coef(model1)[2], digits = 2), + ") * x" + ) + } + + output$regEqn <- renderText(expr = message) + } + ) + + ### Sample Correlation ---- + observeEvent( + eventExpr = c(input$correlation, userData()), + handlerExpr = { + if (!input$correlation) { + message <- NULL + } else if (is.null(userData())) { + message <- "You must plot points first." + } else if (nrow(userData()) < 3) { + message <- "Create more points to display the correlation value." + } else { + message <- paste( + "Correlation =", + round(cor(userData())["x", "y"], digits = 2) + ) + } + + output$correlation <- renderText(expr = message) + } + ) + + ### Challenge feedback ---- + observeEvent( + eventExpr = c(userData(), challengeId()), + handlerExpr = { + if (is.null(userData())) { + message <- "Please click within the plot to add points." + } else if (nrow(userData()) < 3) { + message <- "Please plot three or more points." + } else { + if (challengeId() == 1) { + message <- ifelse( + test = round(cor(userData())["x", "y"], digits = 2) > -0.8, + yes = "You're on the correct path. Please check the 'Regression line' + box to see how you did for regression.", + no = "Sorry, you're sample correlation is too small. Please add/remove + points and keep trying." + ) + } else if (challengeId() == 2) { + message <- ifelse( + test = round(cor(userData())["x", "y"], digits = 2) < 0.5, + yes = "You're on the correct path. Please check the 'Regression line' + box to see how you did for regression.", + no = "Sorry, you're sample correlation is too large. Please add/remove + points and keep trying." + ) + } else if (challengeId() == 3) { + message <- "Please check the 'Regression line' box to see how you did + for regression." + } else if (challengeId() == 4) { + message <- "Be sure to draw the line first. Please check the 'Regression + line' box to see how you did for regression." + } else if (challengeId() == 5) { + message <- "Be sure to draw the line first. Please check the 'Regression + line' box to see how you did for regression." + } else if (challengeId() == 6) { + message <- ifelse( + test = round(cor(userData())["x", "y"], digits = 1) == 0.6, + yes = "Your correlation is close enough. Use the controls to draw your + guess for the regression line. Please check the 'Regression line' box + to see how you did for regression.", + no = "Your correlation isn't close enough to 0.6. Please add/remove + points and keep trying. You can use the 'Show correlation value' button + to see the current sample correlation value." + ) + } else if (challengeId() == 7) { + message <- ifelse( + test = round(cor(userData())["x", "y"], digits = 1) == -0.5, + yes = "Your correlation is close enough. Use the controls to draw your + guess for the regression line. Please check the 'Regression line' box + to see how you did for regression.", + no = "Your correlation isn't close enough to -0.5. Please add/remove + points and keep trying. You can use the 'Show correlation value' button + to see the current sample correlation value." + ) + } else if (challengeId() == 8) { + message <- ifelse( + test = round(cor(userData())["x", "y"], digits = 1) == -0.2, + yes = "Your correlation is close enough. Use the controls to draw your + guess for the regression line. Please check the 'Regression line' box + to see how you did for regression.", + no = "Your correlation isn't close enough to -0.5. Please add/remove + points and keep trying. You can use the 'Show correlation value' button + to see the current sample correlation value." + ) + } else if (challengeId() == 9) { + sampleCor <- round(cor(userData())["x", "y"], digits = 1) + message <- ifelse( + test = sampleCor >= -0.1 && sampleCor <= 0.1, + yes = "Your correlation is within the bounds. Make sure that your graph + shows a strong non-linear relationship.", + no = "Your correlation isn't between -0.1 and 0.1. Add/remove points + and keep trying. Make sure that your graph shows a non-linear relationship." + ) + + } else if (challengeId() == 10) { + sampleCor <- round(cor(userData())["x", "y"], digits = 1) + message <- ifelse( + test = sampleCor >= 0.4 && sampleCor <= 0.6, + yes = "Your correlation is within the bounds. Make sure that your graph + shows a strong non-linear relationship.", + no = "Your correlation isn't between -0.1 and 0.1. Add/remove points + and keep trying. Make sure that your graph shows a non-linear relationship." + ) + } else if (challengeId() == 11) { + message <- "Use the check boxes to check your work." + } else { + print("ERROR IN CHALLENGE ID") + } + } + + output$feedback <- renderText(expr = message) + } + ) + +} + +# Boast App Call ---- +boastUtils::boastApp(ui = ui, server = server) \ No newline at end of file diff --git a/LICENSE.md b/docs/LICENSE.md similarity index 62% rename from LICENSE.md rename to docs/LICENSE.md index 9ddf92a..3c3e67b 100644 --- a/LICENSE.md +++ b/docs/LICENSE.md @@ -1,6 +1,6 @@ -## creative commons +## Creative Commons -# Attribution-NonCommercial-ShareAlike 4.0 International +# Attribution-ShareAlike 4.0 International Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. @@ -12,9 +12,9 @@ Creative Commons public licenses provide a standard set of terms and conditions * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). -## Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License +## Creative Commons Attribution-ShareAlike 4.0 International Public License -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. +By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. ### Section 1 – Definitions. @@ -22,7 +22,7 @@ a. __Adapted Material__ means material subject to Copyright and Similar Rights t b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. -c. __BY-NC-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. +c. __BY-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. @@ -30,7 +30,7 @@ e. __Effective Technological Measures__ means those measures that, in the absenc f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. -g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. +g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike. h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. @@ -38,47 +38,45 @@ i. __Licensed Rights__ means the rights granted to You subject to the terms and j. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. -k. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. +k. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. -l. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. +l. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. -m. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. - -n. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. +m. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. ### Section 2 – Scope. a. ___License grant.___ - 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: + 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: - A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and + A. reproduce and Share the Licensed Material, in whole or in part; and - B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. + B. produce, reproduce, and Share Adapted Material. - 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. + 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. - 3. __Term.__ The term of this Public License is specified in Section 6(a). + 3. __Term.__ The term of this Public License is specified in Section 6(a). - 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. + 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. - 5. __Downstream recipients.__ + 5. __Downstream recipients.__ A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. - B. __Additional offer from the Licensor – Adapted Material.__ Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. + B. __Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. - 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). + 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). b. ___Other rights.___ - 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. + 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. - 2. Patent and trademark rights are not licensed under this Public License. + 2. Patent and trademark rights are not licensed under this Public License. - 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. + 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. ### Section 3 – License Conditions. @@ -86,33 +84,33 @@ Your exercise of the Licensed Rights is expressly made subject to the following a. ___Attribution.___ - 1. If You Share the Licensed Material (including in modified form), You must: + 1. If You Share the Licensed Material (including in modified form), You must: - A. retain the following if it is supplied by the Licensor with the Licensed Material: + A. retain the following if it is supplied by the Licensor with the Licensed Material: - i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); + i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); - ii. a copyright notice; + ii. a copyright notice; - iii. a notice that refers to this Public License; + iii. a notice that refers to this Public License; - iv. a notice that refers to the disclaimer of warranties; + iv. a notice that refers to the disclaimer of warranties; - v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; - B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and + B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and - C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. + C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. - 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. + 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. - 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. + 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. b. ___ShareAlike.___ In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. -1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. +1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. @@ -122,7 +120,7 @@ In addition to the conditions in Section 3(a), if You Share Adapted Material You Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: -a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and @@ -144,11 +142,11 @@ a. This Public License applies for the term of the Copyright and Similar Rights b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: - 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or + 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or - 2. upon express reinstatement by the Licensor. + 2. upon express reinstatement by the Licensor. - For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. + For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. @@ -158,7 +156,7 @@ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. -b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. +b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.t stated herein are separate from and independent of the terms and conditions of this Public License. ### Section 8 – Interpretation. @@ -170,6 +168,8 @@ c. No term or condition of this Public License will be waived and no failure to d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. -> Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. -> -> Creative Commons may be contacted at creativecommons.org +``` +Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org +``` \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..3284e92 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,10 @@ +# Regression Lines + +[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/) +![experimental](https://img.shields.io/badge/lifecycle-experimental-orange) +![year](https://img.shields.io/badge/year-2019-lightgrey) + +![App Screenshot](../docs/screenshot.png) + +# App Description +In this app, you will explore how the correlation and regression line relate to the points on a scatter plot. diff --git a/docs/screenshot.png b/docs/screenshot.png new file mode 100644 index 0000000..25e418a Binary files /dev/null and b/docs/screenshot.png differ diff --git a/server.R b/server.R deleted file mode 100755 index 5cfd425..0000000 --- a/server.R +++ /dev/null @@ -1,375 +0,0 @@ -library(shiny) -library(Cairo) - -server <- function(input, output,session) { - - # Create a spot where we can store additional - # reactive values for this session - c <- reactiveValues(right=c(sample(1:11,1))) - - - observeEvent(input$newchallenge,{ - c$right=sample(1:11,1) - - }) - - observeEvent(input$nextbutton, { - updateTabItems(session, "tabs", "overview") - }) - - observe({ - if (input$newchallenge > 0){ - val$x <- NULL - val$y <- NULL - }}) - - - # Clear the points on button click - observe({ - if (input$clear > 0){ - val$x <- NULL - val$y <- NULL - - }}) - - observe({ - input$clear - updateSliderInput(session,"slope",value = 0) - updateSliderInput(session, "intercept", value =0) - }) - - observe({ - if(input$clear > 0){ - updateCheckboxInput(session=session, inputId ="yourownline", label = "Create your own line",value = FALSE ) - updateCheckboxInput(session=session, inputId ="correlation", label = "Show correlation",value = FALSE ) - updateCheckboxInput(session=session, inputId ="regressionline", label = "Show regression",value = FALSE ) - - } - }) - - observe({ - input$newchallenge - updateSliderInput(session,"slope",value = 0) - updateSliderInput(session, "intercept", value =0) - }) - - observe({ - if(input$newchallenge > 0){ - updateCheckboxInput(session=session, inputId ="yourownline", label = "Create your own line",value = FALSE) - updateCheckboxInput(session=session, inputId ="correlation", label = "Show correlation",value = FALSE) - updateCheckboxInput(session=session, inputId ="regressionline", label = "Show regression",value = FALSE) - }}) - - - observeEvent(input$nextbutton, { - - updateTabItems(session, "tabs", "overview2") - - }) - - observeEvent(input$start, { - updateTabItems(session, "tabs", "regression") - }) - - observeEvent(input$inst2,{ - sendSweetAlert( - session = session, - title = "Instruction:", - type = "info", - print("1. Click New Challenge to get a challenge.\n2. Create your own line by entering the values for both slope and intercept.\n3. Create points by clicking in the plot.\n4. Show the regression line to do a competition.\n5. Click clear points to clean both points and regression lines.") - ) - }) - - - output$yourline <- renderText({ - - paste("Equation of your line:y =",input$intercept,"+", input$slope,"* x") - - }) - - - output$question1<- renderText({ - - if (c$right == 1){ - "Challenge: Draw some points on a scatterplot that have y = 3 – 2x as their regression and a correlation more than - 0.8 (then check the “Regression line” box to see how you did)." - } - else if (c$right == 2){ - "Challenge: Draw some points on a scatterplot that have y = 2 + 3x as their regression and a correlation less than 0.5 (then check the “Regression line” box to see how you did)." - } - else if (c$right == 3){ - "Challenge: Draw some points on a scatterplot that have y = 2x + 1 as their regression (then check the “Show regression” box to see how you did)." - } - else if (c$right == 4){ - "Challenge: Draw your own line with the equation y = 3 – 2x and then add some points that have that as their regression (then check the “Show regression” box to see how you did)." - } - else if (c$right == 5){ - "Challenge: Draw your own line with the equation y = 2 + 3x and then add some points that have that as their regression (then check the “Show regression” box to see how you did)." - } - else if (c$right == 6){ - "Challenge: Create some points with a correlation of 0.6 and then draw your own line that is your guess at the regression line (then check the “Show regression” box to see how you did)." - } - else if (c$right == 7){ - "Challenge: Create some points with a correlation of -0.5 and then draw your own line that is your guess at the regression line (then check the “Show regression” box to see how you did)." - } - else if (c$right == 8){ - "Challenge: create some points with a correlation of -0.2 and then draw your own line that is your guess at the regression line (then check the “Show regression” box to see how you did)." - } - else if (c$right == 9){ - "Challenge: Create some points that have a strong non-linear relationship but a correlation between -0.1 and 0.1." - } - else if (c$right == 10){ - "Challenge: Create some points that have a strong non-linear relationship but a correlation between 0.4 and 0.6." - } - else if (c$right == 11){ - "Challenge: Create some points that follow a roughly linear pattern and a correlation of 0.5 and then add an outlier to make the correlation go down to 0." - } - }) - - val <- reactiveValues(x=NULL, y=NULL) - - # Listen for clicks - observe({ - # Initially will be empty - if (is.null(input$clusterClick)){ - return() - } - - isolate({ - val$x <- c(val$x, input$clusterClick$x) - val$y <- c(val$y, input$clusterClick$y) - }) - }) - - output$clusterPlot <- renderPlot({ - - tryCatch({ - # Format the data as a matrix - - - data1 <- data.frame(c(val$x, val$y), ncol=2) - - # Try to cluster - if (length(val$x) <= 1){ - stop("We can't cluster less than 2 points") - } - suppressWarnings({ - fit <- Mclust(data) - }) - - mclust2Dplot(data = data1, what = "classification", - classification = fit$classification, main = FALSE, - xlim=c(-2,2), ylim=c(-0.2,5),cex=input$opt.cex, cex.lab=input$opt.cexaxis) - }, error=function(warn){ - # Otherwise just plot the points and instructions - plot(val$x, val$y, xlim=c(-5, 5), ylim=c(-0.2, 5), xlab="X", ylab="Y", - cex=2.5, cex.axis=1.5,pch=16,col="blue") - - if (input$yourownline > 0 ){ - - abline(input$intercept,input$slope,col="red", lwd = "3.8") - - } - output$feedback<-renderText({ - if (c$right == 1){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 2) > -0.8){ - paste("The correlation is correct! - \nPlease check the “Regression line” box to see how you did for regression") - } - else if(length(val$x) >= 3 & round( cor(val$x,val$y),digits = 2) <= -0.8){ - paste("Sorry,correlation <= -0.8 - \nPlease add other points or try again for the correlation. - \nPlease check the “Regression line” box to see how you did for regression") - } - } - - else if(c$right == 2){ - if(length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 2) < 0.5){ - paste("The correlation is correct! - \nPlease check the “Regression line” box to see how you did for regression") - } - else if(length(val$x) >= 3 & round( cor(val$x,val$y),digits = 2) >= 0.5){ - paste("Sorry, correlation >= 0.5 - \nPlease add other points or try again for the correlation. - \nPlease check the “Regression line” box to see how you did for regression") - } - } - - else if (c$right == 3){ - if(length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3){ - paste("Please check the “Show regression” box to see how you did for regression") - } - } - - else if (c$right == 4){ - if(is.null(val$x) == TRUE){ - paste("Please draw the line first.") - } - else if (length(val$x) < 3){ - paste("Please add more points ") - } - else if (length(val$x >= 3)){ - paste("Please check the “Show regression” box to see how well do the lines match") - } - } - - else if (c$right == 5){ - if(is.null(val$x) == TRUE){ - paste("Please draw the line first.") - } - else if (length(val$x) < 3){ - paste("Please add more points ") - } - else if (length(val$x >= 3)){ - paste("Please check the “Show regression” box to see how well do the lines match") - } - } - - else if (c$right == 6){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) == 0.6){ - paste("The correlation is correct! - \nPlease guess and draw the regression line. - \nThen check the “Regression line” box to see how you did.") - } - else if(length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) != 0.6){ - paste("Sorry,correlation is not equal to 0.6 - \nPlease add other points or try again for the correlation. - \nYou can check the “Show correlation” box to see the current correlation.") - } - } - - else if (c$right == 7){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) == -0.5){ - paste("The correlation is correct! - \nPlease guess and draw the regression line. - \nThen check the “Regression line” box to see how you did.") - } - else if(length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) != -0.5){ - paste("Sorry,correlation is not equal to -0.5 - \nPlease add other points or try again for the correlation. - \nYou can check the “Show correlation” box to see the current correlation.") - } - } - - else if (c$right == 8){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) == -0.2){ - paste("The correlation is correct! - \nPlease guess and draw the regression line. - \nThen check the “Regression line” box to see how you did.") - } - else if(length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) != -0.2){ - paste("Sorry,correlation is not equal to -0.2 - \nPlease add other points or try again for the correlation. - \nYou can check the “Show correlation” box to see the current correlation.") - } - } - - else if(c$right == 9){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) >= -0.1 & round( cor(val$x,val$y),digits = 1) <= 0.1){ - paste("The correlation is correct! - \nPlease make sure that your graph shows a strong non-linear correlation.") - } - else if (length(val$x) >= 3 & (round( cor(val$x,val$y),digits = 1) < -0.1 | round( cor(val$x,val$y),digits = 1) > 0.1)){ - paste("Sorry, correlation is not between -0.1 and 0.1 - \nPlease add other points or try again for the correlation. - \nAlso, please make sure that your graph shows a strong non-linear correlation.") - } - } - - else if (c$right == 10){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3 & round( cor(val$x,val$y),digits = 1) >= 0.4 & round( cor(val$x,val$y),digits = 1) <= 0.6){ - paste("The correlation is correct! - \nPlease make sure that your graph shows a strong non-linear correlation.") - } - else if (length(val$x) >= 3 & (round( cor(val$x,val$y),digits = 1) < 0.4 | round( cor(val$x,val$y),digits = 1) > 0.6)){ - paste("Sorry, correlation is not between 0.4 and 0.6 - \nPlease add other points or try again for the correlation. - \nAlso, please make sure that your graph shows a strong non-linear correlation.") - } - } - - else if (c$right == 11){ - if (length(val$x) < 3 | is.null(val$x) == TRUE){ - paste("Please click to add more points.") - } - else if (length(val$x) >= 3){ - paste("You can check the “Show correlation” box to see the current correlation.") - } - } - - }) - - if (input$regressionline == "TRUE" & length(val$x) >= 3 ){ - - abline(lm(val$y ~ val$x, data = data1),lwd = "4") - - mod_name <-lm(val$y ~ val$x, data = data1) - mod_name$coeff[2] - - output$regression_equation<-renderText({ - - - # paste("Regression Equation : y =",round(mod_name$coeff[2],digits = 2)," * x +",round(mod_name$coeff[1],digits = 2 )) - paste("Regression Equation : y =",round(mod_name$coeff[1],digits = 2),"+",round(mod_name$coeff[2],digits = 2),"* x") - - - }) - } - - - else if (input$regressionline == "TRUE" & length(val$x) < 3 ){ - output$regression_equation<-renderText({ - - paste("Please click to add more points.") - - })} - - - else if (input$regressionline == "TRUE" & length(val$x) < 3 ){ - output$regression_equation<-renderText({ - paste("Please click to add more points.") - }) - - } - if (input$correlation == "TRUE" & length(val$x) >= 3 ){ - - - output$correlation<-renderText({ - paste( "Correlation = ",round( cor(val$x,val$y),digits = 5)) - - }) - } - - else if (input$correlation == "TRUE" & length(val$x) < 3 ){ - output$correlation<-renderText({ - paste("Please click to add more points.") - - }) - } - }) - }) -} - diff --git a/ui.R b/ui.R deleted file mode 100755 index 86b3c1a..0000000 --- a/ui.R +++ /dev/null @@ -1,213 +0,0 @@ -library(shinydashboard) -library(shiny) -library(shinyjs) -library(shinyBS) -library(shinyWidgets) - -ui <- dashboardPage(skin = "yellow", - dashboardHeader(title = "Regression Line"), - dashboardSidebar( - sidebarMenu( - id ="tabs", - menuItem("Prerequistes",tabName = "prerequisite2",icon = icon("book")), - menuItem("Overview", tabName = "overview2",icon = icon("dashboard")), - menuItem("Challenge", tabName = "regression",icon = icon("cogs")) - ) - ), - dashboardBody( - tags$head( - tags$link(rel = "stylesheet", type = "text/css", href = "Feature.css"), - - tags$style(HTML( - '.popover-title{ - color:black; - font-size:18px; - background-color: orange - }' - )) - - ), - - tabItems( - - #Prerequiste tab - tabItem(tabName = "prerequisite2", - h3(strong("Background: Regression Line")),br(), - h4(strong("Correlation:")), - h4(tags$li("Correlation measures the strength of the linear association between two variables.")), - h4(tags$li("Correlation is always between -1 and +1 (-1 when the points fall exactly on a downhill line and +1 when the points fall exactly on an uphill line).")), - h4(tags$li("Correlation does not change when you change the units of measurement by adding/subtracting/multiplying/dividing every value by the same number.")), - h4(tags$li("Correlation is not appropriate as a measure of association for non-linear patterns.")), - h4(tags$li("Correlation is strongly affected by outliers.")), - h4(strong("Regression Lines:")), - h4(tags$li("The regression line provides a straight line that describes how the average for a response variable Y changes as an explanatory variable X changes. ")), - h4(tags$li("The regression line has the linear form telling you the best prediction for Y when you know that the variable X has a specific value x:")), - div(style = "text-align:center",h4("Predicted Y value = a + b*x")), - h4("- In this case “a” is the intercept (what you predict for Y when x = 0) and “b” is the slope (how much the average value of Y goes up for each unit of x). The slope b will always have the same sign as the correlation."), - h4(tags$li("The regression line is the straight line that makes the standard deviation of the vertical distances of the data points from the line as small as possible. (Remember that standard deviation measures variability and we want to keep the variability around the line as small as possible.)")), - h4(tags$li("The regression line is not appropriate when the relationship between x and y is not described well by a straight line.")), - h4(tags$li("The regression line is not appropriate when an outlier is driving the relationship.")), - br(), - - div(style = "text-align:center", - bsButton("nextbutton", "Go to the overview", icon("wpexplorer"), size = "medium",style = "warning")) - ), - - # Overview tab content - tabItem(tabName = "overview2", - tags$a(href='http://stat.psu.edu/', tags$img(src='logo.png', align = "left", width = 180)), - br(), - br(), - br(), - h3(strong("About:")), - h4("In this App, you will explore how the correlation and regression line relate to the points on a scatterplot."), - br(), - h3(strong("Instructions:")), - h4(tags$li("Click New Challenge to get a challenge.")), - h4(tags$li("Create your own line by entering the values for both slope and intercept.")), - h4(tags$li("Create points by clicking in the plot.")), - h4(tags$li("Show the regression line to compute and display the regression line.")), - h4(tags$li("Click RESET to clean both points and regression lines.")), - div(style = "text-align:center", - bsButton("start", "GO", icon("bolt"), size = "large",style = "warning")), - br(), - h3(strong("Acknowledgements:")), - h4("This app was developed and coded by Caihui Xiao and further updated by Zhiliang Zhang and Jiajun Gao.", - " This app is based on extending the idea in the WH freeman applet at http://digitalfirst.bfwpub.com/stats_applet/generic_stats_applet_5_correg.html.", - " Special thanks to Sitong Liu for help on some programming issues.") - - ), - - # Second tab content - tabItem(tabName = "regression", - - #change the color of slide - - tags$style(HTML(".js-irs-0 .irs-single, .js-irs-0 .irs-bar-edge, .js-irs-0 .irs-bar {background: orange}")), - tags$style(HTML(".js-irs-1 .irs-single, .js-irs-1 .irs-bar-edge,.js-irs-1 .irs-bar-edge, .js-irs-1 .irs-bar {background: orange}")), - - #buttons - div(style="display: inline-block;vertical-align:top;", - div(style="display: inline-block;vertical-align:top;", - tags$a(href='https://shinyapps.science.psu.edu/',tags$img(src='homebut.PNG', width = 19)) - ), - circleButton("inst2",icon = icon("info"), status = "myClass",size = "xs") - - ), - - # Add a title - titlePanel("Explore the regression line"), - - br(), - - - verbatimTextOutput("question1"), - tags$style(type='text/css', '#question1 {font-weight:bold;font-family: sans-serif;font-size: 20px;background-color: #ffffff; color: black;}'), - - wellPanel(style = "background-color: #ffffff;", - - # fluidRow( - # div(style="display: inline-block;vertical-align:top;", - # circleButton("inst2",icon = icon("question",class = "glyphicon glyphicon-info-sign"), size = "xs"), - # div(style="display: inline-block;vertical-align:top;", - # tags$a(href='https://shinyapps.science.psu.edu/',tags$img(src='homebut.PNG', width = 15)) - # ) - # ) - # - # ), - - fluidRow( - column(2, offset=2, actionButton("newchallenge","New Challenge", style="color: #ffffff; background-color: orange")), - - column(2, offset=2, actionButton("clear", "RESET", style="color: #ffffff; background-color: orange")) - ), - - - bsPopover("inst2", " ", "Click to show the instruction for this challenge", place = "bottom"), - bsPopover("clear", " ", "Click RESET to start over this challenge", place = "right"), - - - - - - fluidRow( - - column(2, - checkboxInput ("yourownline", "Create your own line")), - column(4, sliderInput("intercept", - "Choose the intercept:", - min = -10, - max = 10, - value = 5, - step = 0.01)), - column(4, sliderInput("slope", - "Choose the slope:", - min = -10, - max = 10, - value = 2, - step = 0.01)) - ), - - #numeric input format for slope and intercept - # column(2, - # numericInput("slope", "Enter Slope", 0,step=0.1)), - # - # - # column(2, - # numericInput("intercept", "Enter Intercept", 0,step=0.1) - # ) - - - fluidRow( - - column(2, checkboxInput("regressionline", "Show regression", FALSE)) - - # column(8, conditionalPanel(style = "background-color: #ffffff;","input.regressionline !=0",verbatimTextOutput('regression_equation'))), - # tags$head(tags$style(HTML("#regression_equation {font-size: 18px;background-color: #ffffff}"))) - - # tags$style(type='text/css', '#regression_equation {background-color: #ffffff; font-size: 20px;color: black;}') - - - ), - fluidRow( - - - column(2, checkboxInput("correlation", "Show correlation", FALSE)) - #column(8, conditionalPanel(style = "background-color: white;","input.correlation !=0",verbatimTextOutput('correlation'))), - # tags$style(type='text/css', '#correlation {background-color: #ffffff;font-size: 18px; color: black;}') - - ) - ), - - - # Add a row for the main content - fluidRow( - tags$style(type='text/css', '#feedback {background-color: #ffffff; color: black;}'), - - # Create a space for the plot output - - column(8, plotOutput( - "clusterPlot", "100%", "500px", click="clusterClick" - )), - - bsPopover("clusterPlot"," ","Click points on the graph to create your plot", trigger = "hover",place="top"), - - column(4, - column(12, conditionalPanel(style = "background-color: white;","input.yourownline !=0",verbatimTextOutput('yourline'))), - column(12, conditionalPanel(style = "background-color: white;","input.regressionline !=0",verbatimTextOutput('regression_equation'))), - column(12, conditionalPanel(style = "background-color: white;","input.correlation !=0",verbatimTextOutput('correlation'))), - br(), - verbatimTextOutput('feedback'), - - tags$head(tags$style(HTML("#yourline {font-weight:bold;font-family: sans-serif;font-size: 18px;color: red;background-color: #ffffff}"))), - tags$head(tags$style(HTML("#regression_equation {font-weight:bold;font-family: sans-serif;font-size: 18px;background-color: #ffffff}"))), - tags$head(tags$style(HTML("#correlation {font-weight:bold;font-family: sans-serif;font-size: 18px;background-color: #ffffff}"))), - tags$head(tags$style(HTML("#feedback {font-size: 18px;font-family: sans-serif;background-color: #ffffff}"))) - - ) - ) - - ) - ) - ) -) diff --git a/www/Feature.css b/www/Feature.css deleted file mode 100644 index c3b3183..0000000 --- a/www/Feature.css +++ /dev/null @@ -1,27 +0,0 @@ -/*.skin-blue .main-header>.navbar { -background-color: #1E407C; -} -.content-wrapper,.right-side { -background-color: white; -} -.skin-blue .main-header .logo { -background-color: #1E407C; -color: white; -} -.skin-blue .main-header .logo:hover { -background-color: black; -} -aside.main-sidebar { -background-color: black !important; -} -.main-header .logo { -font-family: "Georgia", Times, "Times New Roman", serif; -font-weight: bold; -font-size: 15px; -}*/ - -.btn-myClass { - background-color: #000000; - border: none; - color: white; -} \ No newline at end of file diff --git a/www/homebut.PNG b/www/homebut.PNG deleted file mode 100644 index d14951b..0000000 Binary files a/www/homebut.PNG and /dev/null differ diff --git a/www/logo.png b/www/logo.png deleted file mode 100755 index 9af78bc..0000000 Binary files a/www/logo.png and /dev/null differ