gpt4 book ai didi

r - R中lm(y~.)中点的含义

转载 作者:行者123 更新时间:2023-12-03 14:34:10 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Meaning of ~. (tilde dot) argument?

(1 个回答)


4年前关闭。




我试图在其他人编写的代码中理解 R 中这条语句的含义。

mymodel = lm(gene ~ ., data = mydata) 
mydata如下:
> mydata
gene cna rs11433683 PC1 PC2
TCGA.BH.A0C0 270.7446 0.1291 0 270.7446 0.1291
TCGA.A2.A3XY 87.9092 0.0128 1 87.9092 0.0128
TCGA.XX.A89A 255.1346 0.1530 1 255.1346 0.1530

我已经浏览了 R 帮助部分以了解如何 .被解释。我明白 .通常不使用,但这是我发现的
help(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’


help(terms.formula)

AllowDotAsName: normally . in a formula refers to the remaining variables contained in data. Exceptionally, . can be treated as a name for non-standard uses of formulae.

data: a data frame from which the meaning of the special symbol . can be inferred. It is unused if there is no . in the formula.



但是,我不太确定这些陈述的含义。有人能给我一个简单的例子,说明在我上面提到的语句和数据的上下文中它的含义吗?

最佳答案

in the context of a data argument of model fitting functions and means ‘all columns not otherwise in the formula’



和盒子上写的一模一样!

所以与
 mymodel = lm(gene ~ ., data = mydata) 

你得到除 gene 以外的所有变量这是在 mydata在公式的 RHS 上:
   cna + rs11433683 + PC1 + PC2

就我所见,引用的短语清晰明确(……但您也可以通过尝试几个小例子来看到它)

唯一可能不明显的是,如果您不提供 data,它会做什么。论点(但这是在您的报价中提到的 terms.formula 的帮助下回答的)。

关于r - R中lm(y~.)中点的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45655679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com