Learn R Programming

forestecology (version 0.2.0)

predict.comp_bayes_lm: Make predictions based on fitted Bayesian model

Description

Applies fitted model from comp_bayes_lm() and returns posterior predicted values.

Usage

# S3 method for comp_bayes_lm
predict(object, newdata, ...)

Arguments

object

Output of comp_bayes_lm(): A list of {a_star, b_star, mu_star, V_star} posterior hyperparameters

newdata

A data frame of type focal_vs_comp in which to look for variables with which to predict.

...

Currently ignored<U+2014>only included for consistency with generic.

Value

A vector of predictions with length equal to the input data.

See Also

Other modeling functions: comp_bayes_lm(), create_bayes_lm_data(), run_cv()

Examples

Run this code
# NOT RUN {
library(dplyr)
library(sf)
library(ggplot2)

# Load in posterior parameter example
# and growth data to compare to
data(comp_bayes_lm_ex, growth_ex)

predictions <- focal_vs_comp_ex %>%
  mutate(growth_hat = predict(comp_bayes_lm_ex, focal_vs_comp_ex))

predictions %>%
  ggplot(aes(growth, growth_hat)) +
  geom_point() +
  geom_abline(slope = 1, intercept = 0)
# }

Run the code above in your browser using DataLab