Skip to contents

Generate predictions from a femtofit object using the prediction function supplied at fit time.

Usage

# S3 method for class 'femtofit'
predict(object, newdata, ...)

Arguments

object

A femtofit object.

newdata

New data for prediction. The format depends on the prediction function provided to fit().

...

Additional arguments passed to the prediction function.

Value

Predictions, as returned by the prediction function.

Details

For predict() to work, a predict_fn must have been provided when calling fit(). The prediction function should have signature function(params, newdata, ...) where params is a named list of parameter values.

Examples

if (FALSE) { # \dontrun{
# Linear regression example
x <- 1:10
y <- 2 + 3*x + rnorm(10, sd = 0.5)

# Fit with prediction function
result <- fit(
  function(a, b, log_sigma) {
    sigma <- exp(log_sigma)
    predicted <- a + b * x
    loglik_normal(predicted, sigma, y)
  },
  params = c(a = 0, b = 1, log_sigma = 0),
  predict_fn = function(params, newdata) {
    params$a + params$b * newdata
  }
)

# Predict for new x values
predict(result, newdata = c(11, 12, 13))
} # }