compute_model_prediction {ggvis} | R Documentation |
Fit a 1d model, then compute predictions and (optionally) standard errors over an evenly spaced grid.
compute_model_prediction(x, formula, ..., model = NULL, se = FALSE, level = 0.95, n = 80L, domain = NULL, method) compute_smooth(x, formula, ..., span = 0.75, se = FALSE)
x |
Dataset-like object to model and predict. Built-in methods for data frames, grouped data frames and ggvis visualisations. |
formula |
Formula passed to modelling function. Can use any variables from data. |
... |
arguments passed on to |
model |
Model fitting function to use - it must support R's standard
modelling interface, taking a formula and data frame as input, and
returning predictions with |
se |
include standard errors in output? Requires appropriate method of
|
level |
the confidence level of the standard errors. |
n |
the number of grid points to use in the prediction |
domain |
If |
method |
Deprecated. Please use |
span |
Smoothing span used for loess model. |
compute_model_prediction
fits a model to the data and makes
predictions with it. compute_smooth
is a special case of model
predictions where the model is a smooth loess curve whose smoothness is
controlled by the span
parameter.
A data frame with columns:
|
regularly spaced grid
of |
|
predicted value from model |
|
upper and lower bounds of
confidence interval (if |
|
the
standard error (width of the confidence interval) (if |
# Use a small value of n for these examples mtcars %>% compute_model_prediction(mpg ~ wt, n = 10) mtcars %>% compute_model_prediction(mpg ~ wt, n = 10, se = TRUE) mtcars %>% group_by(cyl) %>% compute_model_prediction(mpg ~ wt, n = 10) # compute_smooth defaults to loess mtcars %>% compute_smooth(mpg ~ wt) # Override model to suppress message or change approach mtcars %>% compute_model_prediction(mpg ~ wt, n = 10, model = "loess") mtcars %>% compute_model_prediction(mpg ~ wt, n = 10, model = "lm") # Set the domain manually mtcars %>% compute_model_prediction(mpg ~ wt, n = 20, model = "lm", domain = c(0, 8)) # Plot the results mtcars %>% compute_model_prediction(mpg ~ wt) %>% ggvis(~pred_, ~resp_) %>% layer_paths() mtcars %>% ggvis() %>% compute_model_prediction(mpg ~ wt) %>% layer_paths(~pred_, ~resp_)