In this part of my Shiny app, I'll do a 'linear model' (lm()) regression, using the variables the user selects. There are three inputs:
input$lmTrendFunis aselectInput(), with the optionsc("Linear", "Exponential", "Logarithmic", "Quadratic", "Cubic"):selectInput("lmTrendFun", "Select the model for your trend line.", choices = c("Linear", "Exponential", "Logarithmic", "Quadratic", "Cubic"))The second input is
input$lmDep, and it's aselectInput()too. I created aupdateSelectInputfirst inside anobserve()reactive function, so the choices are the column names from the importedtibble.The third input is
input$lmIndand it's acheckboxGroupInput(), the choices being all the column names other than the one that's already theinput$lmInd.
From that I want this output: the lm() (or rather, summary.lm() or summary(lm())) result for those variables. If I knew which they were, it would be simple:
if(input$lmTrendFun == "Linear"){
form <- yname ~ x1 + x2
}else if(input$lmTrendFun == "Exponential"){
form <- yname~ exp(x1) + exp(x2)
}else if(input$lmTrendFun == "Logarithmic"){
form <- yname~ log(x1) + log(x2)
}else if(input$lmTrendFun == "Quadratic"){
form <- yname ~ poly(x1, 2) + poly(x2, 2)
}else if(input$lmTrendFun == "Cubic"){
form <- y ~ poly(x1, 3) + poly(x2, 3)
}
[...]
lm(form, data = .)
where the data (.) has the columns yname, x1 and x2.
However, I don't. So I believe I need some more generic function that can create the formula. How can this be done?