Description Usage Arguments Details Value Note Author(s) Examples
Likelihood ratio and extra sumofsquares tests with multiple lm
or nls
models nested within one common model. This function is most useful when the nested functions are all at the same level; otherwise use anova()
or lrtest()
which are more flexible.
1 2 3 4 5 6 
sim 
The results of one 
... 
More model results that are nested subsets of the model in 
com 
The results of one 
sim.name, sim.names 
A string vector of “names” for simple model in 
com.name 
A single “name” string for the complex model in 
x 
An object from 
anova
and lrtest
(from lmtest) provide simple methods for conducting extra sumofsquares or likelihood ratio tests when one model is nested within another model or when there are several layers of simple models all sequentially nested within each other. However, to compare several models that are nested at the same level with one common more complex model, then anova()
and lrtest()
must be repeated for each comparison. This repetition can be eliminated with lapply()
but then the output is voluminous. This function is designed to remove the repetitiveness and to provide output that is compact and easy to read.
The main function returns a matrix with as many rows as model comparisons and columns of the following types:
DfO
The error degreesoffreedom from the subset (more simple) model.
RSSO
, logLikO
The residual sumofsquares (from extraSS
) or loglikelihood (from lrt
) from the subset (more simple) model.
DfA
The error degreesoffreedom from the com=
model.
RSSA
, logLikA
The residual sumofsquares (from extraSS
) or loglikelihood (from lrt
) from the com=
model.
Df
The difference in error degreesoffreedom between the two models.
SS
, logLik
The difference in residual sumofsquares (from extraSS
) or loglikelihood (from lrt
) between the two models.
F
, Chisq
The corresponding F (from extraSS
) or Chisquare (from lrt
) test statistic.
Pr(>F)
, Pr(>Chisq)
The corresponding pvalue.
This function is experimental at this point. It seems to work fine for lm
and nls
models. An error will be thrown by extraSS
for other model classes, but lrt
will not (but it has not been thoroughly tests for other models).
Derek H. Ogle, derek@derekogle.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  ## Example data
df < data.frame(x=c(1,2,3,4,5,6,7,8,9,10),
y=c(4,6,5,7,9,8,7,12,16,22),
z=as.factor(rep(c("A","B"),each=5)),
w=as.factor(rep(c("A","B"),times=5)))
df$x2 < df$x^2
## Linear (lm()) models
# ... regression
fit.0 < lm(y~1,data=df)
fit.1 < lm(y~x,data=df)
fit.2 < lm(y~x2+x,data=df)
extraSS(fit.0,fit.1,com=fit.2)
lrt(fit.0,fit.1,com=fit.2)
# ... show labels for models
extraSS(fit.0,fit.1,com=fit.2,
sim.names=c("Null Model","Linear"),com.name="Quadratic")
lrt(fit.0,fit.1,com=fit.2,
sim.names=c("Null Model","Linear"),com.name="Quadratic")
# ... dummy variable regression
fit.2b < lm(y~x*z,data=df)
extraSS(fit.0,fit.1,com=fit.2b)
lrt(fit.0,fit.1,com=fit.2b)
# ... ANOVAs
fit.1 < lm(y~w,data=df)
fit.2 < lm(y~w*z,data=df)
extraSS(fit.0,fit.1,com=fit.2)
lrt(fit.0,fit.1,com=fit.2)
## Nonlinear (nls()) models
fit.0 = nls(y~c,data=df,start=list(c=10))
fit.1 = nls(y~a*x+c,data=df,start=list(a=1,c=1))
fit.2 = nls(y~b*x2+a*x+c,data=df,start=list(a=1,b=0.3,c=10))
extraSS(fit.0,fit.1,com=fit.2)
lrt(fit.0,fit.1,com=fit.2)
## General leastsquares (gls()) models
## Not run:
require(nlme)
fit.0 < gls(y~1,data=df,method="ML")
fit.1 < gls(y~x,data=df,method="ML")
fit.2 < gls(y~x2+x,data=df,method="ML")
lrt(fit.0,fit.1, com=fit.2)
## will return an error ... does not work with gls() models
# extraSS(fit.0,fit.1, com=fit.2)
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.