Calculate predicted results of the dependent variable from a model with
parameters set up as for the likeli and anneal
functions. These predicted results are useful for various statistical
calculations when compared to observed results from a dataset.
Usage
predicted_results(model, par, var, source_data, ...)
Arguments
model
Model function to use to calculate predicted results.
par
List of parameters for which likelihood is being estimated.
All elements in par must be numeric vectors.
var
List object with the source for all other non-parameter arguments
and data used by model, pdf, or any sub-functions.
source_data
Data frame containing any needed source data.
...
Any other data that may be needed by the model or any of its
sub-functions. This is an alternative to providing the data in var;
however, passing values in var is strongly recommended.
Details
The parameters for this function are set up exactly as they are in
anneal and likeli. See those pages for details
on how to do this.
Extra list members in var are ignored, so if
you have set up a var list for use with likeli or
anneal, you can use that list with predicted_results
without removing arguments for the PDF.
Value
A vector of predicted results, one for each observation in
source_data.
Examples
## Use the included crown_rad dataset
data( crown_rad )
## Create our model function - crown radius is a linear function of DBH.
## DBH is a column of data from the crown_rad dataset; a and b are single
## parameter values.
model <- function (a, b, DBH) {a + b * DBH}
## Create our parameters list and set values for a and b
par <- list(a = 1.12, b = 0.07)
## Create a place to put all the other data needed by
## the model and PDF, and indicate that DBH comes from
## the column marked "DBH" in the dataset
var <- list(DBH = "DBH")
predicted <- predicted_results(model, par, var, crown_rad)
## Calculate R2 - proportion of variance explained by the model relative to
## that explained by the simple mean of the data
meanrad <- mean(crown_rad$Radius)
sse <- (crown_rad$Radius - predicted)^2
sst <- (crown_rad$Radius - meanrad)^2
R2 <- 1 - (sum(sse)/sum(sst))