knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(modelCathRes) library(dplyr, quietly = T, warn.conflicts = F) library(ggplot2)
Validate the interpolation of cathode resistance with
findLogFunction()
with generated data.Validate the functions
modelCathResLm()
andmodelCathResLme()
.
#' generateCathRes #' #' Makes fake cathode resistance value based on a + b log(age) #' #' @param x age of pot #' @param a a coefficient #' @param b b coefficient #' @param error error added to output #' #' @return numeric #' #' #' generateCathRes <- function(x, a = .6, b = 0.02, error = 0.02 ) { stopifnot(x > 0) return(a + b * log(x) + rnorm(1, 0 , error)) } # generate df with data for 1st group (df) age <- 1:2000 cath_res <- purrr::map_dbl(age, .f = generateCathRes) df <- data.frame( age = age, cath_res = cath_res ) # generate df with data for 2nd group (df2) cath_res2 <- purrr::map_dbl(age, .f = generateCathRes, a = .5, b = 0.03) df2 <- data.frame( age = age, cath_res = cath_res2 ) df2 <- bind_rows(df, df2) df2$group <- rep(c("A", "B"), each = length(age * 2)) # Saves data for testing #write.csv(df2, "../tests/testthat/generated_res_data.csv")
findLogFunction
and modelCathResLm
# Plots data ggplot(df, aes(x = age, y = cath_res)) + geom_point(shape = 21, fill = "white")+ labs(title = "Generated Data - group A") # Validate model Lm findLogFunction(df, age = age, res = cath_res, coeff = T )
modelCathResLme
modLmer <- modelCathoResLme( df2, group, age, cath_res ) # Résultats du modèle coef(modLmer)$group
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.