# ==========================================================================
# Package: Cognitivemodels
# File: cognitivemodel-methods.R
# Author: Jana B. Jarecki
# ==========================================================================
# ==========================================================================
# Methods for the Lego-style Cognitive Model
# ==========================================================================
# Define S3 methods for the class 'cognitivemodel'
#' Adds a component to a cognitivemodel via `+`
#'
#' @export
`+` <- function (e1, e2) { UseMethod("+") }
#' @export
`+.default` <- function (e1, e2) { .Primitive("+")(e1, e2) }
#' @method + csm
#' @export
`+.csm` <- function(e1, e2) {
x_name <- .abbrDeparse(substitute(e2))
if (inherits(e2, "cm")) {
return(e1$add_model(e2, x_name = x_name))
}
if (inherits(e2, "function")) {
return(e1$add_fun(e2))
}
}
#' Ends building a cognitivemodel via `+`
#'
#' @param obj a model object of class 'cognitivemodel'
#' @param ... other arguments (ignored)
#' @export
end <- function(obj, ...) { UseMethod("end") }
#' @export
end.csm = function(obj, ...) {
return(obj$end())
}
#' Adds a function to a cognitivemodel via `+`
#'
#' @param obj a model object of class 'cognitivemodel'
#' @param ... other arguments (ignored)
#' @export
fun <- function(obj, ...) { UseMethod("fun") }
#' @export
fun.csm = function(obj, ...) {
return(obj$add_fun(...))
}
#' Estimates free parameters of a cognitvemodel generated via `+`
#'
#' @param obj a model object of class 'cognitivemodel'
#' @param ... other arguments passed to the cognitive model fitting
#' @export
fit <- function(obj, ...) { UseMethod("fit") }
#' @export
fit.csm <- function(obj, ...) {
return(obj$fit(...))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.