marginalPrediction: marginalizes prediction functions

Description Usage Arguments Value Examples

View source: R/mp.R

Description

monte-carlo integration of prediction functions

Usage

1
2
3
4
marginalPrediction(data, vars, n, model, uniform = TRUE, points,
  int.points, aggregate.fun = function(x) sum(x)/length(x),
  predict.fun = function(object, newdata) predict(object, newdata =
  newdata), weight.fun = NULL)

Arguments

data

a data.frame which contains the columns specified by vars and at least one additional column. should correspond to the set of columns used to train the model.

vars

a character vector corresponding to a strict subset of the columns in data.

n

an integer vector of length two giving the resolution of the uniform or random grid on vars for the first element, and the number of the rows of the data to be sampled without replacement for the second element.

model

an object which can be passed to predict.fun to compute predictions. presumably this object represents a model fit.

uniform

logical indicating whether to create the grid on vars uniformly or to sample without replacement from the empirical distribution of those vars.

points

a named list which gives specific points for vars. specifying this argument overrides uniform.

int.points

a integer vector giving indices of the points in data to marginalize over.

aggregate.fun

what function to aggregate the predictions with. this function takes a single argument x and returns a vector. the default is sum(x) / length(x). If weight.fun is used, this function must also take a numeric parameter w.

predict.fun

what function to generate predictions using model. default is the predict method for model. this function must have two arguments, object and newdata.

weight.fun

a function to construct weights for aggregate.fun. this allows Monte-Carlo integration on a grid without assuming a uniform distribution for said grid. the function should take two arguments, design and data, both of which are data.frames of the same column (but different row) dimension, and should return a numeric vector of the same length as the number of rows in design. If this argument is used aggregate.fun must also have an argument w which is the result of weight.fun.

Value

a data.table with columns for predictions and vars.

Examples

1
2
3
4
5
6
7
X = replicate(3, rnorm(100))
y = X %*% runif(3)
data = data.frame(X, y)
fit = lm(y ~ ., data)

marginalPrediction(data.frame(X), "X2", c(10, 25), fit,
  aggregate.fun = function(x) c("mean" = mean(x), "variance" = var(x)))

mmpf documentation built on Oct. 24, 2018, 9:04 a.m.