Description Usage Arguments Details Author(s) Examples
Run Analysis take as input two sets of values (input and output data) and run a series of analysis outputing statistics and graphs to check how well the two datasets fit each other.
1 | Run_analysis(output_data, input_data, title, cor, comment = NULL)
|
output_data |
Model predictions |
input_data |
Original data |
title |
String used to name the plots and the exported files |
cor |
Hexadecimal or color name used to color details in plots |
comment |
Comment to printed in the .txt statistical file results |
#' @title Run simulation #' @name Run_simulation #' @author Marcos Alves mppalves@gmail.com #' @description Function to take as input a testing formula, LSUs and predictors #' and output staticts and plots that describe how good the formula is #' simmulating the original data. #' @usage Run_simulation(func, w, x, input_data, title, cor ="red", comment = NULL) #' @param func R formula to be evaluated #' @param w LSU values #' @param x secondary parameter (preciptation, radiation, temperature or mean #' harvest for example) #' @param input_data data frame with three columns: x variable, LSU, y output #' @param title String used to name the plots and the exported files #' @param cor hexadecimal or color name used to color details in plots #' @param comment Comment useful to copy the formula being analysed #' #' #' @examples #' #' Run_simulation( #' func = y ~ 8.76366 * exp(-0.0163042 * x + (-1.56578 + 0.0103395 * x) * w) * x * w, #' w = input_data$w, #' x = input_data$x, #' input_data = input_data, #' title = "Formula Evaluation Harvest, Yield mean", #' cor = "#217A00", #' comment = "y ~ 8.76366*exp(-0.0163042*x + (-1.56578 + 0.0103395*x)*w)*x*w" #' ) #' @import ggplot2 #' @import stringr #' @export Run_simulation
# tranforming formulas in functions as.function <- function(formula, w, x) cmd <- tail(as.character(formula), 1) exp <- parse(text = cmd) function(w, x) eval(exp, list(w = w, x = x))
evaluate_expression <- function(func, w, x) func <- as.function(func, w, x) y <- do.call(func, list(w = w, x = x)) return(y)
Run_simulation <- function(func, w, x, input_data, title, cor = "red", comment = NULL)
# pre-processing data colnames(input_data) <- c("x", "w", "y")
# simulating y y <- evaluate_expression(func, input_data$w, input_data$x)
# combining the results in a dataframe and constructing a matrix to be ploted combineded_output <- data.frame(x = input_data$x, w = input_data$w, y)
output_data <- combineded_output$y input_data <- input_data$y
# running statistical analysis on the results Run_analysis(output_data, input_data, title, cor, comment)
Marcos Alves mppalves@gmail.com
1 | Run_analysis(output_data, input_data, title = "Model Evaluation harvest", cor = "green")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.