
Last chance! 50% off unlimited learning
Sale ends in
nt
A nested model has a subset of predictor variables from the corresponding full model. Compare a nested linear model with a full model to evaluate the effectiveness of the predictor variables deleted from the full model to define the nested model.
Nest(y, nested.model, full.model, method=c("ls", "logit"),
data=mydata, digits.d=NULL)nt(...)
ls
, the default, or
set to logit
.mydata
by default.R
object, otherwise it simply appears at the console. The components of this object are redesigned in lessR
version 3.3 into (a) pieces of text that form the readable output and (b) a variety of statistics. The readable output are character strings such as tables amenable for viewing and interpretation. The statistics are numerical values amenable for further analysis, such as to be referenced in a subsequent knitr
document. The motivation of these three types of output is to facilitate knitr
documents, as the name of each piece, preceded by the name of the saved object followed by a $, can be inserted into the knitr
document (see examples
).TEXT OUTPUT
out_models
: The specification of the two models compared
out_anova
: Analysis of variance or, for logit, analysis of deviance
STATISTICS
fun.call
: Function call that generated the analysis
anova_tested
: Term that is tested
anova_residual
: Residual df, and either ss and ms or deviance for logit
anova_total
: For logit, total df and deviance
Although not typically needed for analysis, if the output is assigned to an object named, for example, n
, then the complete contents of the object can be viewed directly with the unclass
function, here as unclass(n)
. Invoking the class
function on the saved object reveals a class of {out_all}. The class of each of the text pieces of output is {out_piece}.
R
function anova
function to compare a nested model with a corresponding full model. By default, compare models estimated with ordinary least squares from the R
function lm
, or compare models estimated with logistic regression from the R
function glm
with family="binomial"
. For the logistic analysis, the anova
analysis is with test="Chisq"
.To insure that the same data are analyzed for both models, the fit for the full model is first obtained. Then the data frame that is returned by this analysis is input into the analysis for the nested model. This guarantees that any cases with missing data values missing for the full analysis will have been deleted for the nested analysis. Otherwise rows of data could be retained for the nested analysis that were dropped for the full analysis because of missing data values for the deleted predictor variables. This method also guarantees that cases are not deleted because data was missing on variables not included in full analysis.
anova
, lm
, glm
.mydata <- Read("Reading", format="lessR")
# compare least-squares models
mydata <- Read("Reading", format="lessR")
Nest(Reading, c(Absent), c(Verbal,Absent,Income))
# compare logistic models, save results into an object
# define the full model by adding just the variables
# not found in the reduced model
mydata <- Read("BodyMeas", format="lessR")
n <- Nest(Gender, c(Weight, Hips, Hand, Shoe),
c(Height, Waist, Chest), method="logit")
# view the results
n
# see the names of the available output components
names(n)
Run the code above in your browser using DataLab