View source: R/predicted_results.R
predicted_results | R Documentation |
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.
predicted_results(model, par, var, source_data, ...)
model |
Model function to use to calculate predicted results. |
par |
List of parameters for which likelihood is being estimated.
All elements in |
var |
List object with the source for all other non-parameter arguments
and data used by |
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 |
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.
A vector of predicted results, one for each observation in
source_data
.
## 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.