找回密码
 注册
查看: 397|回复: 0

R语言 VGAM包 cqo()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-10-1 15:30:56 | 显示全部楼层 |阅读模式
cqo(VGAM)
cqo()所属R语言包:VGAM

                                         Fitting Constrained Quadratic Ordination (CQO)
                                         配件约束的二次排序(CQO)

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

A constrained quadratic ordination (CQO; formerly called canonical Gaussian ordination or CGO) model is fitted using the quadratic reduced-rank vector generalized linear model (QRR-VGLM) framework.
一个约束的二次排序(CQO;以前称为规范的高斯协调或CGO),模型拟合的二次降维的向量广义线性模型(QRR VGLM)的框架。


用法----------Usage----------


cqo(formula, family, data = list(), weights = NULL, subset = NULL,
    na.action = na.fail, etastart = NULL, mustart = NULL,
    coefstart = NULL, control = qrrvglm.control(...), offset = NULL,
    method = "cqo.fit", model = FALSE, x.arg = TRUE, y.arg = TRUE,
    contrasts = NULL, constraints = NULL, extra = NULL,
    smart = TRUE, ...)



参数----------Arguments----------

参数:formula
a symbolic description of the model to be fit. The RHS of the formula is applied to each linear predictor. Different variables in each linear predictor can be chosen by specifying constraint matrices.   
一个象征性的模型来描述是合适的。式的RHS被施加到每个线性预测。在每一个线性预测的不同变量,可以选择指定约束矩阵。


参数:family
a function of class "vglmff" (see vglmff-class) describing what statistical model is to be fitted. This is called a “VGAM family function”.  See CommonVGAMffArguments for general information about many types of arguments found in this type of function. Currently the following families are supported: poissonff, binomialff (logit and cloglog links available), negbinomial, gamma2, gaussianff. Sometimes special arguments are required for cqo(), e.g., binomialff(mv = TRUE). Also, quasipoissonff and quasibinomialff may or may not work.   
一个类的函数"vglmff"(vglmff-class)描述统计模型是被安装。这就是所谓的“VGAM家庭功能”。见CommonVGAMffArguments的一般信息,发现这种类型的函数的参数的多种类型的。目前的家庭支持:poissonff,binomialff(logit和cloglog链接提供),negbinomial,gamma2,gaussianff 。有时需要特殊的参数cqo(),例如,binomialff(mv = TRUE)。此外,quasipoissonff和quasibinomialff可能或可能无法正常工作。


参数:data
an optional data frame containing the variables in the model. By default the variables are taken from environment(formula), typically the environment from which cqo is called.  
一个可选的数据框包含在模型中的变量。默认情况下,变量的environment(formula),通常是cqo被称为环境。


参数:weights
an optional vector or matrix of (prior) weights  to be used in the fitting process. Currently, this argument should not be used.  
在嵌合过程中要使用的可选的(现有)的权重向量或矩阵。目前,这种说法不应该使用。


参数:subset
an optional logical vector specifying a subset of observations to be used in the fitting process.  
一个可选的逻辑矢量指定的装配过程中可以使用的观测值的一个子集。


参数:na.action
a function which indicates what should happen when the data contain NAs.  The default is set by the na.action setting of options, and is na.fail if that is unset. The “factory-fresh” default is na.omit.  
一个函数,它表示当数据包含NA的,应该发生什么。默认设置是由na.action的options,是na.fail,如果是没有设置的。 “出厂时的默认是na.omit。


参数:etastart
starting values for the linear predictors. It is a M-column matrix. If M = 1 then it may be a vector. Currently, this argument probably should not be used.  
开始的线性预测值。这是一个M列的矩阵。如果M = 1然后它可能是一个矢量。目前,这种说法可能不应该使用。


参数:mustart
starting values for the  fitted values. It can be a vector or a matrix.  Some family functions do not make use of this argument. Currently, this argument probably should not be used.  
拟合值的初始值。它可以是一个矢量或矩阵。有些家庭功能不使用这种说法。目前,这种说法可能不应该使用。


参数:coefstart
starting values for the coefficient vector. Currently, this argument probably should not be used.  
的系数向量的初始值。目前,这种说法可能不应该使用。


参数:control
a list of parameters for controlling the fitting process. See qrrvglm.control for details.  
的参数,用于控制的嵌合过程的列表。见qrrvglm.control的详细信息。


参数:offset
This argument must not be used.      
不得使用此参数。


参数:method
the method to be used in fitting the model. The default (and presently only) method cqo.fit uses iteratively reweighted least squares (IRLS).  
该方法被用于拟合模型。默认情况下,(目前)的方法cqo.fit使用迭代加权最小二乘(IRLS)。


参数:model
a logical value indicating whether the model frame should be assigned in the model slot.  
一个逻辑值,该值指示是否应该被分配在model插槽的模型框架。


参数:x.arg, y.arg
logical values indicating whether the model matrix and response matrix used in the fitting process should be assigned in the x and y slots. Note the model matrix is the LM model matrix.     
逻辑值模型是否在装修过程中使用的矩阵和响应矩阵应分配在x和y槽。请注意的的模型矩阵是LM模型矩阵。


参数:contrasts
an optional list. See the contrasts.arg of model.matrix.default.  
可选列表。请参阅contrasts.argmodel.matrix.default。


参数:constraints
an optional list  of constraint matrices. The components of the list must be named with the term it corresponds to (and it must match in character format).  Each constraint matrix must have M rows, and be of full-column rank. By default, constraint matrices are the M by M identity matrix unless arguments in the family function itself override these values.  If constraints is used it must contain all the terms; an incomplete list is not accepted. Constraint matrices for x_2 variables are taken as the identity matrix.  
约束矩阵的可选列表。的列表中的组件必须被命名为与它对应的术语(和它必须匹配的字符格式)。每个约束矩阵必须有M行,全列秩。默认情况下,约束矩阵M的M的的身份矩阵,除非在家庭中的参数函数本身覆盖这些值。如果constraints使用它必须包含的所有条款,不接受不完整的名单。 x_2变量的身份矩阵的约束矩阵。


参数:extra
an optional list with any extra information that might be needed by the family function.  
任何额外的信息可能需要的家庭功能的可选列表。


参数:smart
logical value indicating whether smart prediction (smartpred) will be used.  
逻辑值,该值指示是否智能预测(smartpred)的使用。


参数:...
further arguments passed into qrrvglm.control.  
进一步的参数传递到qrrvglm.control。


Details

详细信息----------Details----------

QRR-VGLMs or constrained quadratic ordination (CQO) models are estimated here by maximum likelihood estimation. Optimal linear combinations of the environmental variables are computed, called latent variables (these appear as lv for R=1 else lv1, lv2, etc. in the output).  Here, R is the rank or the number of ordination axes.  Each species' response is then a regression of these latent variables using quadratic polynomials on a transformed scale (e.g., log for Poisson counts, logit for presence/absence responses).  The solution is obtained iteratively in order to maximize the log-likelihood function, or equivalently, minimize the deviance.
QRR-VGLMs或约束的二次排序(CQO)模型的估计最大似然估计。环境变量的最优线性组合来计算,称为潜变量(显示为lv输出R=1其他lv1,lv2,等)。在这里,R级或协调轴的数量。然后,每一个物种的反应是这些潜变量的回归,利用二次多项式转化的规模(例如,log,为泊松计数,Logit的存在/不存在响应)。该溶液得到,以便最大限度地对数似然函数,或等价地,最小化的越轨迭代。

The central formula (for Poisson and binomial species data) is given by
中央公式(泊松分布和二项式物种数据)

where x_1 is a vector (usually just a 1 for an intercept), x_2 is a vector of environmental variables, nu=C^T x_2 is a R-vector of latent variables, e_m is a vector of 0s but with a 1 in the mth position. The eta are a vector of linear/additive predictors, e.g., the mth element is eta_m =   log(E[Y_m]) for the mth species.  The matrices B_1, A, C and D_m are estimated from the data, i.e., contain the regression coefficients.  The tolerance matrices satisfy T_s = -(0.5 D_s^(-1). Many important CQO details are directly related to arguments in qrrvglm.control, e.g., the argument Norrr specifies which variables comprise x_1.
x_1是一个向量(通常只有1对截距项),x_2是环境变量的向量,nu=C^T x_2是R的潜变量的向量, e_m是一个矢量的0,但用了1m个位置。 eta是一个向量的线性/添加剂的预测,例如,m个元素是eta_m =   log(E[Y_m])的m个物种。矩阵B_1,A,C和D_m估计的数据,即包含的回归系数。的耐受性矩阵满足T_s = -(0.5 D_s^(-1)。许多重要的CQO细节有直接关系的参数在qrrvglm.control,例如,参数Norrr指定的变量包括x_1。

Theoretically, the four most popular VGAM family functions to be used with cqo correspond to the Poisson, binomial, normal, and negative binomial distributions. The latter is a 2-parameter model. All of these are implemented, as well as the 2-parameter gamma.  The Poisson is or should be catered for by quasipoissonff and poissonff, and the binomial by quasibinomialff and binomialff. Those beginning with "quasi" have dispersion parameters that are estimated for each species.
从理论上讲,四种最流行的VGAM家庭功能使用cqo对应到泊松分布,二项分布,正常的,负二项分布。后者是一个2  - 参数模型。所有这些都实施,以及作为2参数伽玛。泊松分布或,应照顾quasipoissonff和poissonff,和二项式quasibinomialff和binomialff。 "quasi"开头的每个物种的分散参数估计。

For initial values, the function .Init.Poisson.QO should work reasonably well if the data is Poisson with species having equal tolerances.  It can be quite good on binary data too.  Otherwise the Cinit argument in qrrvglm.control can be used.
的初始值,函数.Init.Poisson.QO工作得很好,如果数据是泊松物种具有相同的公差。它可以是相当不错的二进制数据。否则Cinit参数可用于在qrrvglm.control。

It is possible to relax the quadratic form to an additive model.  The result is a data-driven approach rather than a model-driven approach, so that CQO is extended to constrained additive ordination (CAO) when R=1.  See cao for more details.
这是可能的,放松的二次型添加剂模型。结果是一个数据驱动的方法,而不是一个模型驱动的方法,使CQO扩展到约束添加剂协调(CAO)时R=1。见cao更多详情。

In this documentation, M is the number of linear predictors, S is the number of responses (species). Then M=S for Poisson and binomial species data, and M=2S for negative binomial and gamma distributed species data.
在本文档中,M是线性预测的数量,S的响应数(种)。然后M=S泊松分布和二项式物种的数据,M=2S为负二项分布和伽玛分布的物种数据。


值----------Value----------

An object of class "qrrvglm".  Note that the slot misc has a list component called deviance.Bestof which gives the history of deviances over all the iterations.
对象的类"qrrvglm"。需要注意的是插槽misc有一个列表组件,叫做deviance.Bestof的历史的deviances,所有的迭代。


警告----------Warning ----------

Local solutions are not uncommon when fitting CQO models.  To increase the chances of obtaining the global solution, increase the value of the argument Bestof in qrrvglm.control. For reproducibility of the results, it pays to set a different random number seed before calling cqo (the function set.seed does this).  The function cqo chooses initial values for C using .Init.Poisson.QO() if Use.Init.Poisson.QO = TRUE, else random numbers.
CQO模型拟合时,当地的解决方案的情况并不少见。为了增加成功的机会获得全球性的解决方案,增加值的参数Bestof中qrrvglm.control。对于重复性的结果,它支付给不同的随机数种子,然后再调用cqo(函数set.seed)。函数cqo选择的初始值C使用.Init.Poisson.QO()如果Use.Init.Poisson.QO = TRUE,其他随机数字。

Unless ITolerances = TRUE or EqualTolerances = FALSE, CQO is computationally expensive. It pays to keep the rank down to 1 or 2.  If EqualTolerances = TRUE and ITolerances = FALSE then the cost grows quickly with the number of species and sites (in terms of memory requirements and time).  The data needs to conform quite closely to the statistical model, and the environmental range of the data should be wide in order for the quadratics to fit the data well (bell-shaped response surfaces).  If not, RR-VGLMs will be more appropriate because the response is linear on the transformed scale (e.g., log or logit) and the ordination is called constrained linear ordination or CLO.
除非ITolerances = TRUE或EqualTolerances = FALSE,CQO是计算昂贵的。它支付给向下保持秩为1或2。如果EqualTolerances = TRUE和ITolerances = FALSE那么成本迅速增长的数量的物种和网站(在内存的要求和时间)。数据需要符合相当密切的统计模型,对环境的数据范围要宽,以便在二次方程式,以适应数据以及(钟形响应面)。如果没有,RR-VGLMs会更加合适,因为响应是线性的转换规模(例如,log或罗吉特),被称为约束线性协调统筹或CLO。

Like many regression models, CQO is sensitive to outliers (in the environmental and species data), sparse data, high leverage points, multicollinearity etc.  For these reasons, it is necessary to examine the data carefully for these features and take corrective action (e.g., omitting certain species, sites, environmental variables from the analysis, transforming certain environmental variables, etc.). Any optimum lying outside the convex hull of the site scores should not be trusted.  Fitting a CAO is recommended first, then upon transformations etc., possibly a CQO can be fitted.
像许多的回归模型,CQO是敏感的异常值(在环境和物种的数据),稀疏数据,高杠杆点,多重共线性等,由于这些原因,有必要仔细检查数据,这些功能并采取纠正措施(例如,省略了某些品种,地点,环境变量的分析,把某些环境变量等)。任何最佳外面的凸包的网站得分不应该被信任。拟合曹建议,然后在转换等,可能是一个的CQO可以被安装。

For binary data, it is necessary to have "enough" data.  In general, the number of sites n ought to be much larger than the number of species S, e.g., at least 100 sites for two species. Compared to count (Poisson) data, numerical problems occur more frequently with presence/absence (binary) data.  For example, if Rank = 1 and if the response data for each species is a string of all absences, then all presences, then all absences (when enumerated along the latent variable) then infinite parameter estimates will occur.  In general, setting ITolerances = TRUE may help.
对于二进制数据,它是必要的,以有足够的数据。在一般情况下,网站的数量n应该是远远大于组分s的数量,例如为两个物种,至少有100个网站。数(泊松)数据相比,数值更频繁地出现问题,存在/不存在(二进制)数据。例如,如果Rank = 1,如果每个物种的响应数据的缺勤,那么所有的存在,那么缺勤(枚举时沿潜变量)是一个字符串,然后无限的参数估计值会发生。在一般情况下,设置ITolerances = TRUE可以帮助。

This function was formerly called cgo. It has been renamed to reinforce a new nomenclature described in Yee (2006).
这个函数以前被称为cgo。它已更名为加强中怡康(2006年)中描述的一个新的命名。


注意----------Note----------

By default, a rank-1 equal-tolerances QRR-VGLM model is fitted (see qrrvglm.control for the default control parameters). The latent variables are always transformed so that they are uncorrelated. By default, the argument trace is TRUE meaning a running log is printed out while the computations are taking place.  This is because the algorithm is computationally expensive, therefore users might think that their computers have frozen if trace = FALSE!
默认情况下,的秩等于公差QRR VGLM模型拟合(见qrrvglm.control默认的控制参数)。潜变量都是始终改造,使它们是不相关的。默认情况下,参数traceTRUE意思的运行log打印出来,而计算正在发生。这是因为该算法在计算上是昂贵的,因此,用户可能会认为自己的电脑已经冻结,如果trace = FALSE!

The argument Bestof in qrrvglm.control controls the number of models fitted (each uses different starting values) to the data. This argument is important because convergence may be to a local solution rather than the global solution. Using more starting values increases the chances of finding the global solution.  Always plot an ordination diagram (use the generic function lvplot) and see if it looks sensible.  Local solutions arise because the optimization problem is highly nonlinear, and this is particularly true for CAO.
参数Bestofqrrvglm.control控制的车型配备的数量(每个使用不同的初始值)的数据。“这种说法是很重要的,因为收敛可能是一个本地解决方案,而不是全球性的解决方案。使用更多的初始值增加的机会,寻找全球性解决方案。始终绘制排序图(使用通用的功能lvplot),看看它看上去很聪明。本地解决方案的出现,是因为优化问题是高度非线性的,这是特别真实的曹。

Many of the arguments applicable to cqo are common to vglm and rrvglm.control. The most important arguments are Rank, Norrr, Bestof,  ITolerances, EqualTolerances, isdlv, and MUXfactor.
许多参数适用于cqo是共同vglm和rrvglm.control。最重要的论点是Rank,Norrr,Bestof,ITolerances,EqualTolerances,isdlv和MUXfactor。

When fitting a 2-parameter model such as the negative binomial or gamma, it pays to have EqualTolerances = TRUE and ITolerances = FALSE. This is because numerical problems can occur when fitting the model far away from the global solution when ITolerances = TRUE. Setting the two arguments as described will slow down the computation considerably, however it is numerically more stable.
当安装一个双参数模型,如负二项分布或γ,它支付的EqualTolerances = TRUE和ITolerances = FALSE。这是因为数值时可能出现的问题的全球性解决方案时ITolerances = TRUE拟合模型远离。设置这两个参数的说明将大大减慢计算,但它在数值上更稳定。

In Example 1 below, an unequal-tolerances rank-1 QRR-VGLM is fitted to the hunting spiders dataset, and Example 2 is the equal-tolerances version. The latter is less likely to have convergence problems compared to the unequal-tolerances model. In Example 3 below, an equal-tolerances rank-2 QRR-VGLM is fitted to the hunting spiders dataset. The numerical difficulties encountered in fitting the rank-2 model suggests a rank-1 model is probably preferable. In Example 4 below, constrained binary quadratic ordination (in old nomenclature, constrained Gaussian logit ordination) is fitted to some simulated data coming from a species packing model. With multivariate binary responses, one must use mv = TRUE to indicate that the response (matrix) is multivariate. Otherwise, it is interpreted as a single binary response variable. In Example 5 below, the deviance residuals are plotted for each species. This is useful as a diagnostic plot. This is done by (re)regressing each species separately against the latent variable.
在下面的实施例1中,一个不平等公差秩1 QRR-VGLM嵌合狩猎蜘蛛的数据集,和实施例2是相等的公差版本。后者是不太可能有比较不平等公差模型的收敛性的问题。以下面的实施例3中,一个等于-公差等级-2 QRR-VGLM是嵌合狩猎蜘蛛数据集。在装修的排名-2模型的数值所遇到的困难的秩模型可能是最好的。在实施例4所示,约束二进制二次协调(在旧的命名,约束高斯的罗吉特协调)嵌合来自一个物种堆积模型的一些模拟数据。随着多元二进制反应的,必须使用mv = TRUE表明响应(矩阵)是多元的。否则,它被解释为一个单一的二进制响应变量。在下面的实施例5中,越轨残差绘制每个物种。这是非常有用的作为一个诊断的图。这是通过(重新)分别针对每个物种倒退的潜变量。

Sometime in the future, this function might handle input of the form cqo(x, y), where x and y are matrices containing the environmental and species data respectively.
在未来的某个时候,此功能可以处理输入的形式cqo(x, y),其中x和y含有对环境和物种数据分别是矩阵。


(作者)----------Author(s)----------



Thomas W. Yee.
Thanks to Alvin Sou for converting a lot of the
original FORTRAN code into C.




参考文献----------References----------

A new technique for maximum-likelihood canonical Gaussian ordination. Ecological Monographs, 74, 685–701.
A theory of gradient analysis. Advances in Ecological Research, 18, 271–317.
Constrained additive ordination. Ecology, 87, 203–213.

参见----------See Also----------

qrrvglm.control, Coef.qrrvglm, predictqrrvglm, rcqo, cao, uqo, rrvglm,  poissonff, binomialff, negbinomial, gamma2, lvplot.qrrvglm, perspqrrvglm, trplot.qrrvglm,  vglm, set.seed, hspider.
qrrvglm.control,Coef.qrrvglm,predictqrrvglm,rcqo,cao,uqo,rrvglm,poissonff,binomialff,negbinomial,gamma2,lvplot.qrrvglm,perspqrrvglm,trplot.qrrvglm,vglm,set.seed,hspider 。

Documentation accompanying the VGAM package at http://www.stat.auckland.ac.nz/~yee contains further information and examples.
伴随着VGAM包在http://www.stat.auckland.ac.nz/~仪的文档包含进一步的信息和例子。


实例----------Examples----------


# Example 1; Fit an unequal tolerances model to the hunting spiders data[例1;适合不平等的公差模型的狩猎蜘蛛数据]
hspider[,1:6]=scale(hspider[,1:6]) # Standardize the environmental variables[标准化的环境变量]
set.seed(1234) # For reproducibility of the results[对于结果的再现性]
p1ut = cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
                 Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
                 Trocterr, Zoraspin) ~
           WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
           fam = poissonff, data = hspider, Crow1positive = FALSE,
           EqualTol = FALSE)
sort(p1ut@misc$deviance.Bestof) # A history of all the iterations[历史上所有的迭代]
if(deviance(p1ut) > 1177) warning("suboptimal fit obtained")

## Not run: [#不运行:]
S = ncol(p1ut@y) # Number of species[种数]
clr = (1S+1))[-7] # Omits yellow[省略黄色]
lvplot(p1ut, y = TRUE, lcol = clr, pch = 1:S, pcol = clr, las = 1) # ordination diagram[排序图]
legend("topright", leg = colnames(p1ut@y), col = clr,
       pch = 1:S, merge = TRUE, bty = "n", lty = 1:S, lwd = 2)
## End(Not run)[#(不执行)]
(cp = Coef(p1ut))

(a = cp@lv[cp@lvOrder])  # The ordered site scores along the gradient[沿梯度有序的现场评分]
# Names of the ordered sites along the gradient:[沿梯度的有序网站名称:]
rownames(cp@lv)[cp@lvOrder]
(a = (cp@Optimum)[,cp@OptimumOrder]) # The ordered optima along the gradient[沿渐变的有序最优解]
a = a[!is.na(a)] # Delete the species that is not unimodal[不是单峰的,删除的物种]
names(a)         # Names of the ordered optima along the gradient[沿渐变的名称所订购的最优解]

## Not run: [#不运行:]
trplot(p1ut, whichSpecies = 1:3, log = "xy", type = "b", lty = 1, lwd = 2,
       col = c("blue","red","green"), label = TRUE) -> ii # trajectory plot[轨迹图]
legend(0.00005, 0.3, paste(ii$species[,1], ii$species[,2], sep = " and "),
       lwd = 2, lty = 1, col = c("blue","red","green"))
abline(a = 0, b = 1, lty = "dashed")

S = ncol(p1ut@y) # Number of species[种数]
clr = (1S+1))[-7] # Omits yellow[省略黄色]
persp(p1ut, col = clr, label = TRUE, las = 1) # perspective plot[角度图]

## End(Not run)[#(不执行)]


# Example 2; Fit an equal tolerances model. Less numerically fraught.[例2,上装一个平等的公差模型。减数值困难重重。]
set.seed(1234)
p1et = cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
                 Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
                 Trocterr, Zoraspin) ~
           WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
           fam = poissonff, data = hspider, Crow1positive = FALSE)
sort(p1et@misc$deviance.Bestof) # A history of all the iterations[历史上所有的迭代]
if(deviance(p1et) > 1586) warning("suboptimal fit obtained")
## Not run: [#不运行:]
S = ncol(p1et@y) # Number of species[种数]
clr = (1S+1))[-7] # Omits yellow[省略黄色]
persp(p1et, col = clr, label = TRUE, las = 1)
## End(Not run)[#(不执行)]


# Example 3: A rank-2 equal tolerances CQO model with Poisson data[例3:A级等于公差CQO与泊松数据模型]
# This example is numerically fraught... need IToler = TRUE too.[这个例子是数字充满...需要IToler = TRUE。]
set.seed(555)
p2 = cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
               Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
               Trocterr, Zoraspin) ~
         WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
         fam = poissonff, data = hspider, Crow1positive = FALSE,
         IToler = TRUE, Rank = 2, Bestof = 3, isdlv = c(2.1, 0.9))
sort(p2@misc$deviance.Bestof) # A history of all the iterations[历史上所有的迭代]
if(deviance(p2) > 1127) warning("suboptimal fit obtained")
## Not run: [#不运行:]
lvplot(p2, ellips = FALSE, label = TRUE, xlim = c(-3,4),
       C = TRUE, Ccol = "brown", sites = TRUE, scol = "grey",
       pcol = "blue", pch = "+", chull = TRUE, ccol = "grey")
## End(Not run)[#(不执行)]


# Example 4: species packing model with presence/absence data[实施例4:物种堆积模型与存在/不存在数据]
set.seed(2345)
n = 200; p = 5; S = 5
mydata = rcqo(n, p, S, fam = "binomial", hiabundance = 4,
              EqualTol = TRUE, ESOpt = TRUE, EqualMax = TRUE)
myform = attr(mydata, "formula")
set.seed(1234)
b1et = cqo(myform, binomialff(mv = TRUE, link = "cloglog"), data = mydata)
sort(b1et@misc$deviance.Bestof) # A history of all the iterations[历史上所有的迭代]
## Not run:  lvplot(b1et, y = TRUE, lcol = 1:S, pch = 1:S, pcol = 1:S, las = 1) [#不运行:lvplot(b1et = 1,Y = TRUE,LCOL = 1:S,PCH = 1:S,PCOL = 1:S,拉斯维加斯)]
Coef(b1et)

# Compare the fitted model with the 'truth'[比较合适的模型与“真相”]
cbind(truth=attr(mydata, "ccoefficients"), fitted = ccoef(b1et))


# Example 5: Plot the deviance residuals for diagnostic purposes[例5:绘制用于诊断目的的偏差残差]
set.seed(1234)
p1et = cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
                 Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
                 Trocterr, Zoraspin) ~
           WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
           fam = poissonff, data = hspider, EqualTol = TRUE, trace = FALSE)
sort(p1et@misc$deviance.Bestof) # A history of all the iterations[历史上所有的迭代]
if(deviance(p1et) > 1586) warning("suboptimal fit obtained")
S = ncol(p1et@y)
par(mfrow = c(3,4))
for(ii in 1:S) {
    tempdata = data.frame(lv1 = c(lv(p1et)), sppCounts = p1et@y[,ii])
    tempdata = transform(tempdata, myOffset = -0.5 * lv1^2)

# For species ii, refit the model to get the deviance residuals[对于二种,改装模型的偏差残差]
    fit1 = vglm(sppCounts ~ offset(myOffset) + lv1, fam = poissonff,
                data = tempdata, trace = FALSE)

# For checking: this should be 0[检查:这应该是0]
    print("max(abs(c(Coef(p1et)@B1[1,ii], Coef(p1et)@A[ii,1]) - coef(fit1)))")
    print( max(abs(c(Coef(p1et)@B1[1,ii], Coef(p1et)@A[ii,1]) - coef(fit1))) )

#   # Plot the deviance residuals[#图的偏差残差]
    devresid = resid(fit1, type = "deviance")
    predvalues = predict(fit1) + fit1@offset
    ooo = with(tempdata, order(lv1))
## Not run: [#不运行:]
    with(tempdata, plot(lv1, predvalues + devresid, col = "darkgreen",
                        xlab = "lv1", ylab = "", main = colnames(p1et@y)[ii]))
    with(tempdata, lines(lv1[ooo], predvalues[ooo], col = "blue"))
## End(Not run)[#(不执行)]
}

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-26 21:35 , Processed in 0.025724 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表