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

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

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

                                         Creates a Matrix of Appropriate Dimension
                                         创建一个适当维数的矩阵

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

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

A support function for the argument xij, it generates a matrix of an appropriate dimension.
的支撑函数的参数xij,它会产生一个合适的尺寸的矩阵。


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


fill(x, values = 0, ncolx = ncol(x))



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

参数:x
A vector or matrix which is used to determine the dimension of the answer, in particular, the number of rows.  After converting x to a matrix if necessary, the answer is a matrix of values values, of dimension nrow(x) by ncolx.  
它被用来确定的答案的尺寸,特别是甲向量或矩阵的行数。转换后x为一个矩阵,如果必要的话,答案是values的值的矩阵,的维度nrow(x)由ncolx。


参数:values
Numeric. The answer contains these values, which are recycled columnwise if necessary, i.e., as matrix(values, ..., byrow=TRUE).  
数字。答案包含这些值,如有必要,回收的列,即,作为matrix(values, ..., byrow=TRUE)。


参数:ncolx
The number of columns of the returned matrix. The default is the number of columns of x.  
返回的矩阵的列的数量。默认值是数列的x。


Details

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

The xij argument for vglm allows the user to input variables specific to each linear/additive predictor. For example, consider the bivariate logit model where the first/second linear/additive predictor is the logistic regression of the first/second binary response respectively. The third linear/additive predictor is log(OR) =   eta3, where OR is the odds ratio.  If one has ocular pressure as a covariate in this model then xij is required to handle the ocular pressure for each eye, since these will be different in general. [This contrasts with a variable such as age, the age of the person, which has a common value for both eyes.]  In order to input these data into vglm one often finds that functions fill, fill1, etc. are useful.
xij参数vglm允许用户特定于每个线性/添加剂预测的输入变量。例如,考虑到二元Logit模型,第一/秒线性/添加剂的预测中是logistic回归的第一/第二二进制响应。第三个线性/添加剂的预测是log(OR) =   eta3,OR的比值比。如果一个人在这个模型中的协变量xij需要处理为每只眼睛的眼压,因为这些东西会有所不同,一般的眼内压。与此相反,一个变量如age,年龄的人,有一个共同的价值的两只眼睛。为了这些数据输入到vglm“”人们经常发现的功能<X >,fill“等都是有益的。

All terms in the xij and formula arguments in vglm must appear in the form2 argument too.
xij和formula参数中的所有条款vglm必须出现在form2参数。


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

matrix(values, nrow=nrow(x), ncol=ncolx), i.e., a matrix consisting of values values, with the number of rows matching x, and the default number of columns is the number of columns of x.
matrix(values, nrow=nrow(x), ncol=ncolx)组成的矩阵中的值,即,values,与匹配x,和默认的列数的行的数目是数列x。


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

The effect of the xij argument is after other arguments such as exchangeable and zero. Hence xij does not affect constraint matrices.
xij参数的影响后,其他的参数,如exchangeable和zero。因此xij不影响约束矩阵。

Additionally, there are currently 3 other identical fill functions, called fill1, fill2 and fill3; if you need more then assign fill4 = fill5 = fill1 etc. The reason for this is that if more than one fill function is needed then they must be unique. For example, if M=4 then  xij = op ~ lop + rop + fill(mop) + fill(mop) would reduce to  xij = op ~ lop + rop + fill(mop), whereas xij = op ~ lop + rop + fill1(mop) + fill2(mop) would retain all M terms, which is needed.
此外,还有其他3个相同的fill函数,称为fill1,fill2和fill3,如果你需要更多的分配fill4 = fill5 = fill1等的原因这是,如果一个以上的fill功能是需要的,那么他们必须是唯一的。例如,如果M=4xij = op ~ lop + rop + fill(mop) + fill(mop)将减少至xij = op ~ lop + rop + fill(mop),,而xij = op ~ lop + rop + fill1(mop) + fill2(mop)将保留所有M条款,这些条款是必要的。

In Examples 1 to 3 below, the xij argument illustrates covariates that are specific to a linear predictor. Here, lop/rop are the ocular pressures of the left/right eye in an artificial dataset, and mop is their mean. Variables leye and reye might be the presence/absence of a particular disease on the LHS/RHS eye respectively.     
在下文实施例1~3中,xij参数示出了线性预测特定的协变量。在这里,lop / rop是在人工数据集的左/右眼的眼压力,和mop是他们的平均。变量leye和reye可能会对一个特定的疾病上的左/右轴眼分别的存在/不存在。

In Example 3, the xij argument illustrates fitting the (exchangeable) model where there is a common smooth function of the ocular pressure. One should use regression splines since s in vgam does not handle the xij argument.  However, regression splines such as bs and ns need to have the same basis functions here for both functions, and Example 3 illustrates a trick involving a function BS to obtain this, e.g., same knots. Although regression splines create more than a single column per term in the model matrix, fill(BS(lop,rop)) creates the required (same) number of columns.
在实施例3中,xij参数示出拟合模型(可交换的),其中有一个共同的平滑函数的眼压力。每个人都应该使用云形回归以来svgam不处理xij参数。然而,回归样条曲线,如bs和ns需要为这两个函数具有相同的基础功能,和例3所示的功能BS获得,例如,同样的一招节。虽然回归样条曲线创建多模型矩阵中的单个列,每学期,fill(BS(lop,rop))创建所需的(相同的)的列数。


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


T. W. Yee



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

http://www.stat.auckland.ac.nz/~yee.

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

vglm.control, vglm, multinomial.
vglm.control,vglm,multinomial。


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


fill(runif(5))
fill(runif(5), ncol=3)
fill(runif(5), val=1, ncol=3)

# Generate eyes data for the examples below. Eyes are independent (OR=1).[生成眼睛下面的实施例中的数据。眼睛是独立的(OR = 1)。]
nn = 1000  # Number of people[人数]
eyesdat = data.frame(lop = round(runif(nn), 2),
                     rop = round(runif(nn), 2),
                     age = round(rnorm(nn, 40, 10)))
eyesdat = transform(eyesdat,
    mop = (lop + rop) / 2,       # Mean ocular pressure[平均眼压]
    op  = (lop + rop) / 2,       # Value unimportant unless plotting[价值并不重要,除非策划]
#   op  =  lop,                  # Choose this if plotting[OP =#选择垂耳兔,如果策划]
    eta1 = 0 - 2*lop + 0.04*age, # Linear predictor for left eye[左眼的线性预测]
    eta2 = 0 - 2*rop + 0.04*age) # Linear predictor for right eye[线性预测右眼]
eyesdat = transform(eyesdat,
    leye = rbinom(nn, size=1, prob=logit(eta1, inverse=TRUE)),
    reye = rbinom(nn, size=1, prob=logit(eta2, inverse=TRUE)))

# Example 1[例1]
# All effects are linear[所有的效果是线性的]
fit1 = vglm(cbind(leye,reye) ~ op + age,
            family = binom2.or(exchangeable=TRUE, zero=3),
            data=eyesdat, trace=TRUE,
            xij = list(op ~ lop + rop + fill(lop)),
            form2 =  ~ op + lop + rop + fill(lop) + age)
head(model.matrix(fit1, type="lm"))   # LM model matrix[LM模型矩阵]
head(model.matrix(fit1, type="vlm"))  # Big VLM model matrix[大VLM模型矩阵]
coef(fit1)
coef(fit1, matrix=TRUE)  # Unchanged with 'xij'[不变“XIJ”]
constraints(fit1)
max(abs(predict(fit1)-predict(fit1, new=eyesdat))) # Predicts correctly[预测正确]
summary(fit1)
## Not run: [#不运行:]
plotvgam(fit1, se=TRUE) # Wrong, e.g., because it plots against op, not lop.[错了,例如,因为它的图运,不垂耳。]
# So set op=lop in the above for a correct plot.[所以OP =垂耳,在上面正确的图。]

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



# Example 2[例2]
# Model OR as a linear function of mop[模型或拖把的线性函数]
fit2 = vglm(cbind(leye,reye) ~ op + age,
            binom2.or(exchangeable=TRUE, zero=NULL),
            data=eyesdat, trace=TRUE,
            xij = list(op ~ lop + rop + mop),
            form2 =  ~ op + lop + rop + mop + age)
head(model.matrix(fit2, type="lm"))   # LM model matrix[LM模型矩阵]
head(model.matrix(fit2, type="vlm"))  # Big VLM model matrix[大VLM模型矩阵]
coef(fit2)
coef(fit2, matrix=TRUE)  # Unchanged with 'xij'[不变“XIJ”]
max(abs(predict(fit2)-predict(fit2, new=eyesdat))) # Predicts correctly[预测正确]
summary(fit2)
## Not run: [#不运行:]
plotvgam(fit2, se=TRUE) # Wrong because it plots against op, not lop.[错误的,因为它图运算,而不是垂耳。]

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


# Example 3. This model uses regression splines on ocular pressure.[实施例3。该模型采用回归样条,对眼部的压力。]
# It uses a trick to ensure common basis functions.[它使用的伎俩,以确保共同的基础功能。]
BS = function(x, ...) bs(c(x,...), df=3)[1:length(x),,drop=FALSE] # trick[招]

fit3 = vglm(cbind(leye,reye) ~ BS(lop,rop) + age,
            family = binom2.or(exchangeable=TRUE, zero=3),
            data=eyesdat, trace=TRUE,
            xij = list(BS(lop,rop) ~ BS(lop,rop) +
                                     BS(rop,lop) +
                                     fill(BS(lop,rop))),
            form2 = ~  BS(lop,rop) + BS(rop,lop) + fill(BS(lop,rop)) +
                       lop + rop + age)
head(model.matrix(fit3, type="lm"))   # LM model matrix[LM模型矩阵]
head(model.matrix(fit3, type="vlm"))  # Big VLM model matrix[大VLM模型矩阵]
coef(fit3)
coef(fit3, matrix=TRUE)
summary(fit3)
fit3@smart.prediction
max(abs(predict(fit3)-predict(fit3, new=eyesdat))) # Predicts correctly[预测正确]
predict(fit3, new=head(eyesdat))  # Note the 'scalar' OR, i.e., zero=3[注意“标量或,即,零= 3]
max(abs(head(predict(fit3))-predict(fit3, new=head(eyesdat)))) # Should be 0[应为0]
## Not run: [#不运行:]
plotvgam(fit3, se=TRUE, xlab="lop") # Correct[更正]

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

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-18 11:55 , Processed in 0.021230 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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