#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#'
#'
#' @param dataset Dataset
#' @param dataset Dataset
#' @param rvar The response variable in the model
#' @param rvar The response variable in the model
#' @param evar Explanatory variables in the model
#' @param evar Explanatory variables in the model
#' @param type Model type (i.e., "classification" or "regression")
#' @param type Model type (i.e., "classification" or "regression")
#' @param lev The level in the response variable defined as _success_
#' @param lev The level in the response variable defined as _success_
#' @param size Number of units (nodes) in the hidden layer
#' @param size Number of units (nodes) in the hidden layer
#' @param decay Parameter decay
#' @param decay Parameter decay
#' @param wts Weights to use in estimation
#' @param wts Weights to use in estimation
#' @param seed Random seed to use as the starting point
#' @param seed Random seed to use as the starting point
#' @param check Optional estimation parameters ("standardize" is the default)
#' @param check Optional estimation parameters ("standardize" is the default)
#' @param form Optional formula to use instead of rvar and evar
#' @param form Optional formula to use instead of rvar and evar
#' @param data_filter Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")
#' @param data_filter Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")
#' @param arr Expression to arrange (sort) the data on (e.g., "color, desc(price)")
#' @param arr Expression to arrange (sort) the data on (e.g., "color, desc(price)")
#' @param rows Rows to select from the specified dataset
#' @param rows Rows to select from the specified dataset
#' @param envir Environment to extract data from
#' @param envir Environment to extract data from
#'
#'
#' @return A list with all variables defined in nn as an object of class nn
#' @return A list with all variables defined in nn as an object of class nn
#'
#'
#' @examples
#' @examples
#' nn(titanic, "survived", c("pclass", "sex"), lev = "Yes") %>% summary()
#' nn(titanic, "survived", c("pclass", "sex"), lev = "Yes") %>% summary()
paste0("Length of the weights variable is not equal to the number of rows in the dataset (",format_nr(length(wts),dec=0)," vs ",format_nr(nrow(dataset),dec=0),")")%>%
paste0("Length of the weights variable is not equal to the number of rows in the dataset (",format_nr(length(wts),dec=0)," vs ",format_nr(nrow(dataset),dec=0),")")%>%
#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#'
#'
#' @param x Return value from \code{\link{nn}}
#' @param x Return value from \code{\link{nn}}
#' @param plots Plots to produce for the specified Neural Network model. Use "" to avoid showing any plots (default). Options are "olden" or "garson" for importance plots, or "net" to depict the network structure
#' @param plots Plots to produce for the specified Neural Network model. Use "" to avoid showing any plots (default). Options are "olden" or "garson" for importance plots, or "net" to depict the network structure
#' @param size Font size used
#' @param size Font size used
#' @param pad_x Padding for explanatory variable labels in the network plot. Default value is 0.9, smaller numbers (e.g., 0.5) increase the amount of padding
#' @param pad_x Padding for explanatory variable labels in the network plot. Default value is 0.9, smaller numbers (e.g., 0.5) increase the amount of padding
#' @param nrobs Number of data points to show in dashboard scatter plots (-1 for all)
#' @param nrobs Number of data points to show in dashboard scatter plots (-1 for all)
#' @param incl Which variables to include in a coefficient plot or PDP plot
#' @param incl Which variables to include in a coefficient plot or PDP plot
#' @param incl_int Which interactions to investigate in PDP plots
#' @param incl_int Which interactions to investigate in PDP plots
#' @param shiny Did the function call originate inside a shiny app
#' @param shiny Did the function call originate inside a shiny app
#' @param custom Logical (TRUE, FALSE) to indicate if ggplot object (or list of ggplot objects) should be returned. This option can be used to customize plots (e.g., add a title, change x and y labels, etc.). See examples and \url{https://ggplot2.tidyverse.org} for options.
#' @param custom Logical (TRUE, FALSE) to indicate if ggplot object (or list of ggplot objects) should be returned. This option can be used to customize plots (e.g., add a title, change x and y labels, etc.). See examples and \url{https://ggplot2.tidyverse.org} for options.
#' @param ... further arguments passed to or from other methods
#' @param ... further arguments passed to or from other methods
#'
#'
#' @examples
#' @examples
#' result <- nn(titanic, "survived", c("pclass", "sex"), lev = "Yes")
#' result <- nn(titanic, "survived", c("pclass", "sex"), lev = "Yes")
#' plot(result, plots = "net")
#' plot(result, plots = "net")
#' plot(result, plots = "olden")
#' plot(result, plots = "olden")
#' @seealso \code{\link{nn}} to generate results
#' @seealso \code{\link{nn}} to generate results
#' @seealso \code{\link{summary.nn}} to summarize results
#' @seealso \code{\link{summary.nn}} to summarize results
#' @seealso \code{\link{predict.nn}} for prediction
#' @seealso \code{\link{predict.nn}} for prediction
#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#' @details See \url{https://radiant-rstats.github.io/docs/model/nn.html} for an example in Radiant
#'
#'
#' @param object Return value from \code{\link{nn}}
#' @param object Return value from \code{\link{nn}}
#' @param pred_data Provide the dataframe to generate predictions (e.g., diamonds). The dataset must contain all columns used in the estimation
#' @param pred_data Provide the dataframe to generate predictions (e.g., diamonds). The dataset must contain all columns used in the estimation
#' @param pred_cmd Generate predictions using a command. For example, `pclass = levels(pclass)` would produce predictions for the different levels of factor `pclass`. To add another variable, create a vector of prediction strings, (e.g., c('pclass = levels(pclass)', 'age = seq(0,100,20)')
#' @param pred_cmd Generate predictions using a command. For example, `pclass = levels(pclass)` would produce predictions for the different levels of factor `pclass`. To add another variable, create a vector of prediction strings, (e.g., c('pclass = levels(pclass)', 'age = seq(0,100,20)')
#' @param dec Number of decimals to show
#' @param dec Number of decimals to show
#' @param envir Environment to extract data from
#' @param envir Environment to extract data from
#' @param ... further arguments passed to or from other methods
#' @param ... further arguments passed to or from other methods
#'
#'
#' @examples
#' @examples
#' result <- nn(titanic, "survived", c("pclass", "sex"), lev = "Yes")
#' result <- nn(titanic, "survived", c("pclass", "sex"), lev = "Yes")
i18n$t("This analysis requires a response variable with two levels and one\nor more explanatory variables. If these variables are not available\nplease select another dataset.\n\n")%>%
i18n$t("This analysis requires a response variable with two levels and one\nor more explanatory variables. If these variables are not available\nplease select another dataset.\n\n")%>%
suggest_data("titanic")
suggest_data("titanic")
}else{
}else{
i18n$t("This analysis requires a response variable of type integer\nor numeric and one or more explanatory variables.\nIf these variables are not available please select another dataset.\n\n")%>%
i18n$t("This analysis requires a response variable of type integer\nor numeric and one or more explanatory variables.\nIf these variables are not available please select another dataset.\n\n")%>%
suggest_data("diamonds")
suggest_data("diamonds")
}
}
}elseif(not_available(input$nn_evar)){
}elseif(not_available(input$nn_evar)){
if(input$nn_type=="classification"){
if(input$nn_type=="classification"){
i18n$t("Please select one or more explanatory variables.")%>%
i18n$t("Please select one or more explanatory variables.")%>%
suggest_data("titanic")
suggest_data("titanic")
}else{
}else{
i18n$t("Please select one or more explanatory variables.")%>%
i18n$t("Please select one or more explanatory variables.")%>%
suggest_data("diamonds")
suggest_data("diamonds")
}
}
}else{
}else{
"available"
"available"
}
}
})
})
.nn<-eventReactive(input$nn_run,{
.nn<-eventReactive(input$nn_run,{
nni<-nn_inputs()
nni<-nn_inputs()
nni$envir<-r_data
nni$envir<-r_data
withProgress(
withProgress(
message=i18n$t("Estimating model"),value=1,
message=i18n$t("Estimating model"),value=1,
do.call(nn,nni)
do.call(nn,nni)
)
)
})
})
.summary_nn<-reactive({
.summary_nn<-reactive({
if(not_pressed(input$nn_run)){
if(not_pressed(input$nn_run)){
return(i18n$t("** Press the Estimate button to estimate the model **"))
return(i18n$t("** Press the Estimate button to estimate the model **"))
}
}
if(nn_available()!="available"){
if(nn_available()!="available"){
return(nn_available())
return(nn_available())
}
}
summary(.nn())
summary(.nn())
})
})
.predict_nn<-reactive({
.predict_nn<-reactive({
if(not_pressed(input$nn_run)){
if(not_pressed(input$nn_run)){
return(i18n$t("** Press the Estimate button to estimate the model **"))
return(i18n$t("** Press the Estimate button to estimate the model **"))