linear_model {OptimModel} | R Documentation |
Linear model, gradient, and starting values
Description
Linear model, gradient, and starting values.
Usage
linear_model(theta, x)
Arguments
theta |
Vector of model parameters intercept and slope. See details. |
x |
Matrix, possibly from |
Details
The linear model is given by:
y = x * \theta \text{, where}
x is a matrix
, possibly generated from model.matrix
()
\theta
is a vector of linear parameters
Value
Let N = nrow(x). Then
linear_model(theta, x) returns a numeric vector of length N.
attr(linear_model, "gradient")(theta, x) returns x.
attr(linear_model, "start")(x, y) returns solve(t(x) * x) * t(x) * y
Author(s)
Steven Novick
See Also
Examples
set.seed(123)
d = data.frame( Group=factor(rep(LETTERS[1:3], each=5)), age=rnorm(15, mean=20, sd=3) )
d$y = c(80, 100, 120)[unclass(d$Group)] - 3*d$age + rnorm(nrow(d), mean=0, sd=5)
X = model.matrix(~Group+age, data=d) ## This is the "x" in linear.model()
theta = c(80, 20, 40, -3) ## Intercept, effect for B, effect for C, slope for age
linear_model(theta, x=X)
attr(linear_model, "gradient")(theta, x=X)
attr(linear_model, "start")(x=X, y=d$y)
[Package OptimModel version 2.0-1 Index]