## This is a generic function with different arguments depending on the class of the
## first argument. The generic form is
pod (x, ...)
## If the first argument to pod is a formula suitable for defining a linear model,
"pod"(formula, data = sys.parent(), group, subset, weights, na.action, mean.function = c("pod", "common", "parallel", "general"), singular.ok = FALSE, contrasts = NULL, offset, control = nls.control(), ...)
## If the first argument to pod is the result of a linear model fit, the following
## function call is used. All the arguments for pod.formula can also be passed to
## pod.lm.
"pod" (x, group, mean.function, control, ...)
## The following related function require a pod fit as the first argument:
"anova"(object,scale=0,test="F",...)
"plot"(x, colors=1:nlevels(x$group), pch=1:nlevels(x$group),key="topleft",identify=FALSE, xlab="Linear Predictor", ylab=as.character(c(formula(x)[[2]])), ...)
"plot"(x, colors=1:nlevels(x$group), pch=1:nlevels(x$group), key="topleft", identify=FALSE, xlab="Linear Predictor", ylab=as.character(c(formula(x)[[2]])), ...)
FALSE
is recommended.nls.control
function."topleft"
, in which case a legend is added to
the top left corner of the plot; other choices include "bottomright"
.
If key
is a vector of two coordinates, the legend is drawn at the coordinates
specified. If key
is FALSE, no key is drawn; if TRUE, you can place the
key interactively by clicking on the plot.mean.function="pod"
, a list of class pod, with the following components
nls
fit.mean.function
has any other value, an object of class c("pod.lm", "lm")
is returned. Since the only method for pod.lm objects is a plotting method,
except for plotting these objects behave like lm objects.
y ~ x1 + x2 + x3
,
where the right-side variables can be any valid R variables, such as
transformations, but NOT
factors or interactions (if you want to include these, you need to create the
dummy variables yourself). The right-hand side variables must also be linearly
independent. We also specify a grouping variable z with, say, g levels. Let
$Gi$ be a dummy variable with values equal to 1 when $z=i$, and
zero otherwise. The pod mean function is then has the nonlinear mean function
$$E(y|x,z) = \beta_0 + \beta'x + \sum_{j=2}^g G_j(\theta_{0j} + \theta_{ij}\beta'x)$$
This is a nonlinear mean function that specifies that the response depends on the predictors
only through one linear combination, that the dependence is linear, but the slope
and intercept may be different for each group.The pod mean function is easily fit using nls
. For example, if z has two levels,
a nonlinear mean function that would work is
y ~ b0 + b1*x1 + b2*x2 + b3*x3 + G2*(th02 + th12*(b1*x1 + b2*x2 + b3*x3))
.
Starting values can be determined by fitting the parallel mean function, for this is a
linear mean function and easily fit.
The function pod
automates this process; you need only input the linear
part of the mean function, and pod
does the rest.
The function anova.pod
is a little different from the generic anova
function. It
fits and compares all four mean functions that can be fit with the
pod function: (1) no group effect; (2) parallel
within group method; (3) pod mean function; (4) mean function with all main effects and
two-factor
interactions with the grouping variable.
The function plot
will plot the response versus the fitted linear
combination for either the common, parallel or pod models. There is no 2D plot for
the general model.
Objects of class pod have methods defined for the generic functions
print
,
summary
,
coef
,
anova
,
deviance
,
vcov
,
resid
,
formula
,
fitted
,
df.residual
and
predict
. podresponse
returns the values of the response.
Weisberg, S. (2005) Applied Linear Regression, third edition. New York: Wiley.
nls
, lm
, nls.control
head(ais)
m1 <- pod(LBM ~ Ht + Wt + RCC, data= ais, group= Sex)
anova(m1) # compare four models
plot(m1) # draw the plot
m2 <- update(m1, mean.function="parallel")
plot(m2)
Run the code above in your browser using DataLab