R/nonlinear.R

#' Nonlinear relationships
#'
#' This function allows you to visualize different linear models (polynomial, piecewise linear, and splines) to address nonlinear relationships between y and x.
#'
#' @keywords polynomial, piecewise, splines
#'
#' @import shiny
#' @import ggplot2
#' @import dplyr
#' @import splines
#'
#' @export
#'
#' @examples
#' \dontrun{
#' nonlinear()
#' }
#'
nonlinear = function(){

  ## generate data

  #set.seed(1)
  data.nonlin = data.frame(x = runif(100, 0, 1)) %>%
    mutate(y = -30*(x-.5)^2 + 100*(x-.5)^4 + rnorm(100, 0, .3))

  ## line

  ## UI definition
  ui <- fluidPage(
    headerPanel('Slope and intercept for a simple linear regression'),
    sidebarPanel(
      selectInput("polydrop", "Choose the degree of the polynomial",
                  c("1" = 1,
                    "2" = 2,
                    "3" = 3,
                    "4" = 4,
                    "5" = 5,
                    "6" = 6
                    ))
    ),
    mainPanel(
      plotOutput("randomplot")
    )
  )

  ## Server definition
  server <- function(input, output) {


    fittedpoly <- reactive({
      text = "Boo!"
    })


    output$randomplot <- renderPrint({
      text
    })

  }
  ## run app
  shinyApp(ui = ui, server = server)

}
fairy1991/coolpackage documentation built on May 16, 2019, 9:59 a.m.