Description Usage Arguments Details Value Author(s) References See Also Examples
Fits marginal models, by default using maximum likelihood.
1 2 3 4 5  MarginalModelFit(dat, model, ShowSummary = TRUE, MaxSteps = 1000, MaxStepSize = 1,
MaxError = 1e20, StartingPoint = "Automatic", MaxInnerSteps = 2,
ShowProgress = TRUE, CoefficientDimensions="Automatic", Labels="Automatic",
ShowCoefficients = TRUE, ShowParameters = FALSE, ParameterCoding = "Effect",
ShowCorrelations = FALSE, Method = "ML", Title = "Summary of model fit")

dat 
vector of frequencies or data frame 
model 
list specified eg as 
ShowSummary 
Whether or not to execute 
MaxSteps 
integer: maximum number of steps of the algorithm 
MaxStepSize 
number greater than 0 and at most 1: step size 
MaxError 
numeric: maximum error term 
StartingPoint 
vector of starting frequencies corresponding to all cells in the manifest table 
MaxInnerSteps 
nonnegative integer: only used for latent variable models, indicates number of steps in M step of EM algorithms 
ShowProgress 
boolean or integer: FALSE for no progress information, TRUE or 1 for information at every step, an integer k for information at every kth step 
CoefficientDimensions 
numeric vector of dimensions of the table in which the coefficient vector is to be arranged 
Labels 
list of characters or numbers indicating labels for dimensions of table in which the coefficient vector is to be arranged 
ShowCoefficients 
boolean, indicating whether or not the coefficients are to be displayed 
ShowParameters 
boolean, indicating whether or not the parameters (computed from the coefficients) are to be displayed 
ParameterCoding 
Coding to be used for parameters, choice of 
ShowCorrelations 
boolean, indicating whether or not to show the correlation matrix for the estimated coefficients 
Method 
character, choice of "ML" for maximum likelihood or "GSK" for the GSK method 
Title 
title of computation to appear at top of screen output 
The data can be a data frame or vector of frequencies. MarginalModelFit
converts a data frame dat
to a vector of
frequencies using c(t(ftable(dat)))
.
The model specification is fairly flexible. We first describe the most typical way to specify the model.
The model itself should typically first be written in the form of a constraint vector as
B'θ(A'π) = 0
where B' is a contrast matrix, A' is matrix, normally of zeroes and ones, such that A'pi gives a vector of marginal probabilities, and the function theta yields
a list of (marginal) coefficients. The model is then specified as model=list(bt,coeff,at)
where bt
is the matrix B', at
is the matrix A', and coeff
represents the vector of coefficients using the generalized explog notation. For most of the models in the book, bt
can be obtained directly using ConstraintMatrix
,
coeff
can be obtained directly using SpecifyCoefficient
, and at
can be obtained directly using MarginalMatrix
.
Note that CMM does not permit the C and X matrix in the model
C'θ(A'π) = Xβ
to be specified for use in the programme. The model has to be rewritten in terms of constraints as above, which is normally straightforward to do with the use of ConstraintMatrix
.
For many purposes, estimates and standard errors for a beta vector as in the equation above can still be obtained using the optional argument ShowParameters=TRUE
.
There are two ways to specify coeff
. The first is using the generalized explog notation, in which case coeff[[1]]
should be a list of matrices, and
coeff[[2]]
should be a list of predefined functions of the same length. The second is to set coeff
equal to a predefined function; for example, marginal loglinear models
are obtained by setting coeff="log"
.
The model can be specified in various other ways: as model=list(coeff,at)
, model=list(bt,coeff)
, model=at
, or even just model=coeff
.
Furthermore, the model
B'θ(A'π) = d
with d a nonzero vector is specified in the form model=list(bt,coeff,at,d)
.
To specify the simultaneous model
B'θ(A'π) = 0\\ \logπ=Xβ
the extended model specification model=list(margmodel,x)
should be used, where margmodel
has one of the above forms, and x
is a design matrix,
which can be obtained using DesignMatrix
. Fitting is often more efficient by specifying a loglinear model for the joint distribution in this way rather than
using constraints.
The default onscreen output when running fit=MarginalModelFit(...)
is given by summary(fit)
. Important here is the distinction between coefficients and parameters, briefly
described above. Standard output gives the coefficients. These are that part of model
without the bt
matrix, eg if the model is list(bt,coeff,at)
then the coefficients are list(coeff,at)
. If other coefficients are needed, ModelStatistics
can be used.
Latent variable models can be specified: if the size of the table for which model
is specified is a multiple of the the size of the
observed frequencies specified in dat
, it is assumed this is due to the presence of latent variables. With respect to vectorization,
the latent variables are assumed to change their value fastest.
Convergence may not always be achieved with MaxStepSize=1
and a lower value may need to be used, but not too low or convergence is slow. If the step size is too large,
a typical error message is "system is computationally singular: reciprocal condition number = 1.35775e19"
Most of the following are included in any output. Use summary()
to get a summary of output.
FittedFrequencies 
Vector of fitted frequencies for the full table (including any latent variables). 
Method 
Fitting method used (currently maximum likelihood, GSK or minimum discrimination information) 
LoglikelihoodRatio 

ChiSquare 

DiscriminationInformation 

WaldStatistic 

DegreesOfFreedom 

PValue 
pvalue based on asymptotic chisquare approximation for likelihood ratio test statistic 
SampleSize 

BIC 

Eigenvalues 

ManifestFittedFrequencies 
For the “coefficients” in the equation bt.coeff(at.pi)=d, the following statistics are available:
ObservedCoefficients 

FittedCoefficients 

CoefficientStandardErrors 

CoefficientZScores 

CoefficientAdjustedResiduals 

CoefficientCovarianceMatrix 

CoefficientCorrelationMatrix 

CoefficientAdjustedResidualCovarianceMatrix 

CoefficientDimensions 

CoefficientTableVariableLabels 

CoefficientTableCategoryLabels 
The “parameters” are certain linear combinations of the coefficients. For example, if the coefficients are log probabilities, then the parameters are the usual loglinear parameters.
Parameters 
For the ith subset of variables, the parameters are obtained by
Parameters[[i]]$ 
The following statistics for the parameters belonging to each subset of variable are available.
Parameters[[i]]$ObservedCoefficients 

Parameters[[i]]$FittedCoefficients 

Parameters[[i]]$CoefficientStandardErrors 

Parameters[[i]]$CoefficientZScores 

Parameters[[i]]$CoefficientAdjustedResiduals 

Parameters[[i]]$CoefficientCovarianceMatrix 

Parameters[[i]]$CoefficientCorrelationMatrix 

Parameters[[i]]$CoefficientAdjustedResidualCovarianceMatrix 

Parameters[[i]]$CoefficientDimensions 

Parameters[[i]]$CoefficientTableVariableLabels 

Parameters[[i]]$CoefficientTableCategoryLabels 
W. P. Bergsma w.p.bergsma@lse.ac.uk
Bergsma, W. P. (1997). Marginal models for categorical data. Tilburg, The Netherlands: Tilburg University Press. http://stats.lse.ac.uk/bergsma/pdf/bergsma_phdthesis.pdf
SampleStatistics
, ModelStatistics
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  # see also the builtin data sets
data(NKPS)
# Fit the model asserting Goodman and Kruskal's gamma is zero for
# Child's attitude toward sex role's (NKPS[,3], three categories) and
# parent's attitude toward sex role's (NKPS[,4], three categories).
coeff = SpecifyCoefficient("GoodmanKruskalGamma",c(3,3))
fit = MarginalModelFit(NKPS[,c(3,4)], coeff )
# Marginal homogeneity (MH) in a 3x3 table AB
# Note that MH is equivalent to independence in the 2x3 table of marginals IR, in which
# the row with I=1 gives the A marginal, and the row with I=2 gives the B marginal
n < c(1,2,3,4,5,6,7,8,9)
at < MarginalMatrix(c("A","B"),list(c("A"),c("B")),c(3,3))
bt < ConstraintMatrix(c("I","R"),list(c("I"),c("R")),c(2,3))
model < list( bt, "log", at)
fit < MarginalModelFit(n,model)
#Output can be tidied up:
fit < MarginalModelFit(n,model,CoefficientDimensions=c(2,3))

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