R/estimate_mdiff_one_examples.R

Defines functions test_estimate_mdiff_one

test_estimate_mdiff_one <- function() {

  # Correct uses -------------------------

  # From raw data, analyze a single column of a data.frame
  estimate <- estimate_mdiff_one(mtcars, mpg)
  estimate
  plot_mdiff_contrast_bs(estimate)

  estimate <- estimate_mdiff_one(mtcars, mpg, population_m = 15, population_s = 2)
  estimate
  plot_mdiff_contrast_bs(estimate)
  
  estimate <- estimate_mdiff_one(mtcars, mpg, conf_level = 0.99)
  estimate
  
  estimate_mdiff_one(data = mtcars, outcome_variable = mpg)
  estimate



  # From raw data, analyze data in a vector
  estimate_mdiff_one(outcome_variable = mtcars$gear)
  estimate_mdiff_one(outcome_variable = mtcars$gear, conf_level = 0.95)
  estimate_mdiff_one(outcome_variable = c(1, 2, 3, 4, 5))

  # From summary data
  estimate_mdiff_one(
    comparison_m = 10, 
    comparison_s = 2, 
    comparison_n = 5, 
    conf_level = 0.95
  )
  estimate_mdiff_one(
    comparison_m = 10, 
    comparison_s = 2, 
    comparison_n = 5, 
    conf_level = 0.99
  )
  estimate_mdiff_one(
    comparison_m = 10, 
    comparison_s = 2, 
    comparison_n = 5, 
    outcome_variable_name = "MyVariable", 
    conf_level = 0.95
  )

  # estimate and then test
  estimate <- estimate_mdiff_one(
    mtcars, 
    mpg, 
    population_m = 20
  )
  test_mdiff_contrast_bs(
    estimate, 
    rope_lower = -1, 
    rope_upper = 1, 
    rope_units = "raw", 
    alpha = 0.05
  )

  # TOSTER::dataTOSTone(
  #   mtcars, 
  #   vars="mpg", 
  #   mu = 20, 
  #   low_eqbound_d = 1/6.026948, 
  #   high_eqbound_d = 1/6.026948, 
  #   alpha = 0.05
  # )


  # Plots
  estimate <- estimate_mdiff_one(
    comparison_m = 10, 
    comparison_s = 2, 
    comparison_n = 5, 
    conf_level = 0.95
  )
  plot_mdiff_contrast_bs(estimate)
  
  mydata <- data.frame(var1 = rnorm(n = 100, m = 100, sd = 15),
                       var2 = rnorm(n = 100, m = 115, sd = 15),
                       var3 = c(rnorm(n = 50, m = 95, sd = 15), rep(NA, 50))
  )
  estimate <- estimate_mdiff_one(mydata, var1)
  plot_mdiff_contrast_bs(estimate)
  
  plot_mdiff_contrast_bs(estimate, ylim = c(0, NA))
  plot_mdiff_contrast_bs(estimate, ylim = c(0, 200))
  plot_mdiff_contrast_bs(estimate, ylim = c(NA, 200))
  plot_mdiff_contrast_bs(estimate, ylab = "Whatever")
  plot_mdiff_contrast_bs(estimate, xlab = "Whatever")
  
  

}
rcalinjageman/esci2 documentation built on Dec. 22, 2021, 1:02 p.m.