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

R语言:formula()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 19:19:04 | 显示全部楼层 |阅读模式
formula(stats)
formula()所属R语言包:stats

                                        Model Formulae
                                         模型公式

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

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

The generic function formula and its specific methods provide a way of extracting formulae which have been included in other objects.
通用功能formula和其具体方法提取公式,已包括在其他对象提供一种方式。

as.formula is almost identical, additionally preserving attributes when object already inherits from "formula".  The default value of the env argument is used only when the formula would otherwise lack an environment.
as.formula几乎是相同的,另外保留属性时object已"formula"继承。 env参数则使用默认值,只有当公式,否则缺乏的环境。


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


formula(x, ...)
as.formula(object, env = parent.frame())

## S3 method for class 'formula'[类formula的方法]
print(x, showEnv = !identical(e, .GlobalEnv), ...)



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

参数:x, object
R object.
R对象。


参数:...
further arguments passed to or from other methods.
通过进一步的论据或其他方法。


参数:env
the environment to associate with the result.
环境关联的结果。


参数:showEnv
logical indicating if the environment should be printed as well.
逻辑说明以及印刷环境应。


Details

详情----------Details----------

The models fit by, e.g., the lm and glm functions are specified in a compact symbolic form. The ~ operator is basic in the formation of such models. An expression of the form y ~ model is interpreted as a specification that the response y is modelled by a linear predictor specified symbolically by model. Such a model consists of a series of terms separated by + operators. The terms themselves consist of variable and factor names separated by : operators. Such a term is interpreted as the interaction of all the variables and factors appearing in the term.
例如,模型拟合,lm和glm功能都在一个紧凑的符号形式指定。 ~运营商基本是在这种模式的形成。表达的形式y ~ model被解释为一个响应y指定model象征性的线性预测模型的规范。这样的模式由一系列+运营商分离的条件。条款本身包含:运营商分离的变量和因素。这样一个长期被解释为在任期内出现的所有变量和因素的相互作用。

In addition to + and :, a number of other operators are useful in model formulae.  The * operator denotes factor crossing: a*b interpreted as a+b+a:b.  The ^ operator indicates crossing to the specified degree.  For example (a+b+c)^2 is identical to (a+b+c)*(a+b+c) which in turn expands to a formula containing the main effects for a, b and c together with their second-order interactions. The %in% operator indicates that the terms on its left are nested within those on the right.  For example a + b %in% a expands to the formula a + a:b.  The - operator removes the specified terms, so that (a+b+c)^2 - a:b is identical to a + b + c + b:c + a:c.  It can also used to remove the intercept term: when fitting a linear model y ~ x - 1 specifies a line through the origin.  A model with no intercept can be also specified as y ~ x + 0 or y ~ 0 + x.
除了+和:,其他一些运营商在模型公式有用。 *运营商表示因素交叉:a*ba+b+a:b解释。 ^运营商表示,穿越到指定的程度。例如(a+b+c)^2这反过来又扩大到含(a+b+c)*(a+b+c),a和b在一起的主要影响其二阶公式c相同相互作用。 %in%运营商表示,在其左侧的条款,在右侧的嵌套。例如a + b %in% a扩展公式a + a:b。 -运营商删除指定的条款,因此,(a+b+c)^2 - a:b是a + b + c + b:c + a:c相同。它也可以用来去除截距项:当拟合线性模型y ~ x - 1指定一个通过原点的线。没有拦截模型,也可以指定为y ~ x + 0或y ~ 0 + x。

While formulae usually involve just variable and factor names, they can also involve arithmetic expressions. The formula log(y) ~ a + log(x) is quite legal. When such arithmetic expressions involve operators which are also used symbolically in model formulae, there can be confusion between arithmetic and symbolic operator use.
虽然公式通常涉及只是变量和因素的名字,他们也可以涉及算术表达式。公式log(y) ~ a + log(x)是完全合法的。当这样的算术表达式涉及运营商也被用来象征模型公式,可以有算术运算和符号运算符的使用之间的混乱。

To avoid this confusion, the function I() can be used to bracket those portions of a model formula where the operators are used in their arithmetic sense.  For example, in the formula y ~ a + I(b+c), the term b+c is to be interpreted as the sum of b and c.
为了避免这种混乱,功能I()可以用于支架的模型公式所在的运营商都在他们的算术意义的部分。例如,公式中的y ~ a + I(b+c),b+c作为解释b和c的总和。

Variable names can be quoted by backticks `like this` in formulae, although there is no guarantee that all code using formulae will accept such non-syntactic names.
变量名可以通过反引号引述like this公式中,虽然不能保证所有的代码使用公式将接受这样的非句法名。

Most model-fitting functions accept formulae with right-hand-side including the function offset to indicate terms with a fixed coefficient of one.  Some functions accept other "specials" such as strata or cluster (see the specials argument of terms.formula).
大多数模型拟合函数接受与右手副作用,包括功能offset表明了一个固定的系数公式。有些函数接受其他“特别”,如strata或cluster(看到specialsterms.formula)参数。

There are two special interpretations of . in a formula.  The usual one is in the context of a data argument of model fitting functions and means "all columns not otherwise in the formula": see terms.formula.  In the context of update.formula, only, it means "what was previously in this part of the formula".
有两个特殊的解释.公式。通常一个是参数模型拟合功能data的背景下,意味着“公式中的所有列,否则”:看到terms.formula。只,在上下文update.formula,这意味着在这个公式的一部分,以前是“。

When formula is called on a fitted model object, either a specific method is used (such as that for class "nls") or the default method.  The default first looks for a "formula" component of the object (and evaluates it), then a "terms" component, then a formula parameter of the call (and evaluates its value) and finally a "formula" attribute.
当formula称为拟合模型对象,无论是具体的方法是使用(例如,类"nls")或默认的方法。默认的第一个"formula"对象的组件(和评估),然后"terms"组件,然后formula调用的参数(和评估其价值),最后一个"formula"属性。

There is a formula method for data frames.  If there is only one column this forms the RHS with an empty LHS.  For more columns, the first column is the LHS of the formula and the remaining columns separated by + form the RHS.
有一个formula数据框的方法。如果是只有一列,形成空左方的RHS。对于更多的列,第一列是LHS和公式+形成的RHS分隔其余列。


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

All the functions above produce an object of class "formula" which contains a symbolic model formula.
上述所有的功能产生一个对象类"formula"其中包含一个象征性的模型公式。


环境----------Environments----------

A formula object has an associated environment, and this environment (rather than the parent environment) is used by model.frame to evaluate variables that are not found in the supplied data argument.
公式对象都有一个关联的环境,这种环境下(而不是父环境)model.frame用来评估未发现在所提供的data参数的变量。

Formulas created with the ~ operator use the environment in which they were created.  Formulas created with as.formula will use the env argument for their environment.  Pre-existing formulas extracted with as.formula will only have their environment changed if env is given explicitly.
与~运营商创建的公式使用中,他们创造了环境。 as.formula创建公式,将他们的环境中使用env参数。 as.formula提取预先存在的公式只会改变他们的环境,如果env给出明确。


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

Statistical models. Chapter 2 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.

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

I, offset.
I,offset。

For formula manipulation: terms, and all.vars; for typical use: lm, glm, and coplot.
对于配方操纵:terms,all.vars;典型用途:lm,glm,coplot。


举例----------Examples----------


class(fo <- y ~ x1*x2) # "formula"[“公式”]
fo
typeof(fo)# R internal : "language"[ŕ内部:“语言”]
terms(fo)

environment(fo)
environment(as.formula("y ~ x"))
environment(as.formula("y ~ x", env=new.env()))


## Create a formula for a model with a large number of variables:[#创建一个与大量的变量模型的公式:]
xnam <- paste("x", 1:25, sep="")
(fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 13:26 , Processed in 0.020400 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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