R/f2ftheta.R

Defines functions f2ftheta

f2ftheta <- function(f, X, n){
  stopifnot(is.function(f))
  if("x" %in% names(formals(f))){
    validate_numeric(x = X)
    if(!is.matrix(X)){
      message("Coercing X to matrix...")
      X <- as.matrix(X)
    }
    output <- function(theta) apply(X, MARGIN = 1, FUN = f, theta = theta)
  } else {
    if("X" %in% names(formals(f))){
      output <- function(theta) f(X = X, theta = theta)
    } else {
      stopifnot(is.numeric(n), n > 0)
      # if(!is.null(X)) message("Supplied X ignored")
      output <- function(theta) rep(unname(theta), n)
    }
  }
  return(output)
}

Try the distfreereg package in your browser

Any scripts or data that you put into this service are public.

distfreereg documentation built on April 4, 2025, 12:30 a.m.