mosaic.glm(vcdExtra)
mosaic.glm()所属R语言包:vcdExtra
Mosaic plots for fitted generalized linear and generalized nonlinear models
马赛克图是拟合广义线性模型和广义非线性模型
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Procduces mosaic plots (and other plots in the strucplot framework) for a log-linear model fitted with glm or for a generalized nonlinear model fitted with gnm.
Procduces配备strucplot的对数线性模型或广义非线性模型配备glm马赛克图(和其他图gnm框架的)。
These methods extend the range of strucplot visualizations well beyond the models that can be fit with loglm. They are intended for models for counts using the Poisson family (or quasi-poisson), but should be sensible as long as (a) the response variable is non-negative and (b) the predictors visualized in the strucplot are discrete factors.
这些方法延长strucplot可视化的范围远远超出了模型,可以适合与loglm。他们的目的是计数的的泊松家庭(或准泊松)模型,而应该是明智的,只要(一)响应变量的非负及(b)可视化的预测strucplot是离散的因素。
用法----------Usage----------
## S3 method for class 'glm'
mosaic(x, formula = NULL, panel = mosaic, type = c("observed", "expected"), residuals = NULL,
residuals_type = c("pearson", "deviance", "rstandard"), gp = shading_hcl, gp_args = list(), ...)
## S3 method for class 'glm'
sieve(x, ...)
## S3 method for class 'glm'
assoc(x, ...)
参数----------Arguments----------
参数:x
A glm or gnm object. The response variable, typically a cell frequency, should be non-negative.
Aglm或gnm对象。响应变量,通常是一个小区的频率,应该是非负的。
参数:formula
A one-sided formula with the indexing factors of the plot separated by '+'. A formula must be provided unless x$data inherits from class "table" – in which case the indexing factors of this table are used, or the factors in x$data (or model.frame(x) if x$data is an environment) exactly cross-classify the data – in which case this set of cross-classifying factors are used.
+是一种片面的分离式的索引因素的图。必须提供的公式,除非x$data继承自类"table"“ - 在这种情况下,此表的索引因素使用,或x$data(或model.frame的因素(X)如果x$data是环境)完全交叉分类的数据 - 在这种情况下,这个组的分类因素。
参数:panel
Panel function used to draw the plot for visualizing the observed values, residuals and expected values. Currently, one of "mosaic", "assoc", or "sieve" in vcd.
面板功能用于绘制可视化的观测值,残差和预期值的图。目前,"mosaic","assoc"或"sieve"中vcd之一。
参数:type
A character string indicating whether the "observed" or the "expected" values of the table should be visualized by the area of the tiles or bars.
一个字符串指示是否"observed"或"expected"表的值应该是可视化的区域的瓷砖或条形。
参数:residuals
An optional array or vector of residuals corresponding to the cells in the data, for example, as calculated by residuals.glm(x), residuals.gnm(x).
一个可选的数组或向量的残差数据中的单元格对应的,例如,如由residuals.glm(x),residuals.gnm(x)计算。
参数:residuals_type
If the residuals argument is NULL, residuals are calculated internally and used in the display. In this case, residual_type can be "pearson", "deviance" or "rstandard". Otherwise (when residuals is supplied), residuals_type is used as a label for the legend in the plot.
如果residuals的说法是NULL,残差计算内部,并在显示器中使用。在这种情况下,residual_type是"pearson","deviance"或"rstandard"。否则(当residuals提供),residuals_type使用作为标签的传说中的图。
参数:gp
Object of class "gpar", shading function or a corresponding generating function (see strucplot Details and shadings). Ignored if shade = FALSE.
对象的类"gpar",遮光功能或相应的生成函数(见strucplot详细和shadings“)。如果忽略阴凉处= FALSE。
参数:gp_args
A list of arguments for the shading-generating function, if specified.
的阴影生成函数,如果指定的参数列表。
参数:...
Other arguments passed to the panel function e.g., mosaic
其他参数传递给panel的功能,例如,mosaic
Details
详细信息----------Details----------
For both poisson family generalized linear models and loglinear models, standardized residuals provided by rstandard (sometimes called adjusted residuals) are often preferred because they have constant unit asymptotic variance.
都泊松家庭广义线性模型和对数线性模型,提供标准化残差rstandard(有时也被称为调整残差)往往是最好的,因为他们有固定单位渐近方差。
The sieve and assoc methods are simple convenience interfaces to this plot method, setting the panel argument accordingly.
sieve和assoc方法是简单方便的接口,该图的方法,设置相应的面板参数。
值----------Value----------
The structable visualized by strucplot is returned invisibly.
structable用strucplot返回不可见的。
(作者)----------Author(s)----------
Heather Turner, Michael Friendly, with help from Achim Zeileis
参见----------See Also----------
glm, gnm, plot.loglm, mosaic
glm,gnm,plot.loglm,mosaic
实例----------Examples----------
GSStab <- xtabs(count ~ sex + party, data=GSS)
# using the data in table form[使用的数据以表格形式]
mod.glm1 <- glm(Freq ~ sex + party, family = poisson, data = GSStab)
res <- residuals(mod.glm1)
std <- rstandard(mod.glm1)
# For mosaic.default(), need to re-shape residuals to conform to data[对于mosaic.default(),需要重新塑造残差数据符合]
stdtab <- array(std, dim=dim(GSStab), dimnames=dimnames(GSStab))
mosaic(GSStab, gp=shading_Friendly, residuals=stdtab, residuals_type="Std\nresiduals",
labeling = labeling_residuals)
# Using externally calculated residuals with the glm() object[使用外部计算残差(GLM)对象]
mosaic.glm(mod.glm1, residuals=std, labeling = labeling_residuals, shade=TRUE)
# Using residuals_type[使用residuals_type]
mosaic.glm(mod.glm1, residuals_type="rstandard", labeling = labeling_residuals, shade=TRUE)
## Ordinal factors and structured associations[#有序因素和结构性协会]
data(Mental)
xtabs(Freq ~ mental+ses, data=Mental)
long.labels <- list(set_varnames = c(mental="Mental Health Status", ses="Parent SES"))
# fit independence model[适合独立模式]
# Residual deviance: 47.418 on 15 degrees of freedom[剩余偏差:47.418 15度的自由]
indep <- glm(Freq ~ mental+ses,
family = poisson, data = Mental)
long.labels <- list(set_varnames = c(mental="Mental Health Status",
ses="Parent SES"))
mosaic(indep,residuals_type="rstandard", labeling_args = long.labels, labeling=labeling_residuals)
# or, show as a sieve diagram[或者,显示筛子图]
mosaic(indep, labeling_args = long.labels, panel=sieve, gp=shading_Friendly)
# fit linear x linear (uniform) association. Use integer scores for rows/cols [适合线性X线性(均匀)的关联。使用行/列的整数分数]
Cscore <- as.numeric(Mental$ses)
Rscore <- as.numeric(Mental$mental)
linlin <- glm(Freq ~ mental + ses + Rscore:Cscore,
family = poisson, data = Mental)
mosaic(linlin,residuals_type="rstandard",
labeling_args = long.labels, labeling=labeling_residuals, suppress=1, gp=shading_Friendly,
main="Lin x Lin model")
## Goodman Row-Column association model fits even better (deviance 3.57, df 8)[#古德曼行列关联模型拟合得更好(偏差3.57,DF 8)]
if (require(gnm)) {
Mental$mental <- C(Mental$mental, treatment)
Mental$ses <- C(Mental$ses, treatment)
RC1model <- gnm(Freq ~ ses + mental + Mult(ses, mental),
family = poisson, data = Mental)
mosaic(RC1model,residuals_type="rstandard",
labeling_args = long.labels, labeling=labeling_residuals, suppress=1, gp=shading_Friendly,
main="RC1 model")
}
############# UCB Admissions data, fit using glm()[############UCB招生数据,配合使用(GLM)]
structable(Dept ~ Admit+Gender,UCBAdmissions)
berkeley <- as.data.frame(UCBAdmissions)
berk.glm1 <- glm(Freq ~ Dept * (Gender+Admit), data=berkeley, family="poisson")
summary(berk.glm1)
mosaic(berk.glm1, gp=shading_Friendly, labeling=labeling_residuals, formula=~Admit+Dept+Gender)
# the same, displaying studentized residuals; note use of formula to reorder factors in the mosaic[相同,显示学生化残差,注意使用公式进行重新排序的因素在镶嵌]
mosaic(berk.glm1, residuals_type="rstandard", labeling=labeling_residuals, shade=TRUE,
formula=~Admit+Dept+Gender, main="Model: [DeptGender][DeptAdmit]")
## all two-way model[#所有双向模式]
berk.glm2 <- glm(Freq ~ (Dept + Gender + Admit)^2, data=berkeley, family="poisson")
summary(berk.glm2)
mosaic.glm(berk.glm2, residuals_type="rstandard", labeling = labeling_residuals, shade=TRUE,
formula=~Admit+Dept+Gender, main="Model: [DeptGender][DeptAdmit][AdmitGender]")
anova(berk.glm1, berk.glm2, test="Chisq")
# Add 1 df term for association of [GenderAdmit] only in Dept A[1 DF的[GenderAdmit]仅系一个术语的关联]
berkeley <- within(berkeley, dept1AG <- (Dept=='A')*(Gender=='Female')*(Admit=='Admitted'))
berkeley[1:6,]
berk.glm3 <- glm(Freq ~ Dept * (Gender+Admit) + dept1AG, data=berkeley, family="poisson")
summary(berk.glm3)
mosaic.glm(berk.glm3, residuals_type="rstandard", labeling = labeling_residuals, shade=TRUE,
formula=~Admit+Dept+Gender, main="Model: [DeptGender][DeptAdmit] + DeptA*[GA]")
anova(berk.glm1, berk.glm3, test="Chisq")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|