R/analysis.R

Defines functions analysis

Documented in analysis

#A generic function that computes some basic preliminary funciotns and graphs
#' This function, given a set of numerical input, return some basic statistical operation
#' @param x set of numerical input, possibly collected into a data frame
#' @param y set of numerical input, possibly collected into a data frame
#'
#' @return mean, variance, standard deviation, maximum value and its position, minimum value
#' and its position, correlation, simple regression, line plot, bar plot, box plot and scatter plot.
#' @export
#'
#' @examples To run an example, please, download an example dataset with this command:
#' data <- data.frame(getDataset()). Then, type and run: analysis(data$Y,data$Italy).
analysis <- function(x,y){
  Mean <- mean(y)
  Var <- var(y)
  StDev <- sd(y)
  Max <- max(y)
  max <- which(y == Max)
  Min <- min(y)
  min <- which(y == Min)
  Cor <- cor(x,y)
  Reg <- lm( y ~ x)
  Sum <- summary(Reg)

  values <- list( "Mean" = Mean, "Variance" = Var, "Standard Deviation" = StDev,
      "Maximum Value" = Max, "Position of the maximun element" = max,
      "Minimum Value"= Min, "Poistion of minimum element" = min,
      "Correlation" = Cor, "Linear Regression" = Sum )
  return(values)
}
unimi-dse/f4836d06 documentation built on Feb. 21, 2020, 2:03 a.m.