Classes: Some classes to simplify making predictions

Description Usage Arguments Value Author(s) Examples

Description

This file defines some classes and methods that are used to make some of the predictions in the corresponding paper's empirical exercise (Calhoun, 2011).

Usage

1
2
3
4
5
6
7
8
CT(model)
Aggregate(model.list, fn)
## S3 method for class 'CT'
predict(object, newdata,...)
## S3 method for class 'Aggregate'
predict(object, newdata,...)

HasMethod(object, method.name)

Arguments

model

An object with a “predict” method.

model.list

A list of objects with “predict” methods.

fn

A function that can take and aggregate a vector: “mean,” for example.

object

A variable belonging to an S3 class.

newdata

A new data set to use to create the new forecasts.

...

For “predict.CT”, additional arguments to pass to the underlying “predict” method. For “predict.Aggregate”, additional arguments to pass to the individual “predict” methods.

method.name

A character vector giving the names of different S3 methods.

Value

“CT” and “Aggregate” return objects with (S3) classes “CT” and “Aggregate” respectively. The “predict” methods each return a single forecast. “HasMethod” returns a logical vector with the same length as “method.name” indicating whether “object” has each method defined.

Author(s)

Gray Calhoun gcalhoun@iastate.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  olddata <- data.frame(y = rnorm(30), x = rnorm(30))
  newdata <- data.frame(y = rnorm(3), x = rnorm(3))

  m1 <- lm(y ~ 1, data = olddata)
  m2 <- lm(y ~ x, data = olddata)

  m3 <- CT(m2)
  m4 <- Aggregate(list(m1, m2, m3), median)

  predict(m3, newdata)
  predict(m4, newdata)

  HasMethod(m1, c("plot", "print", "predict", "median"))

grayclhn/oosanalysis-R-library documentation built on May 17, 2019, 8:33 a.m.