从 R 中的公式对象中删除 "Formula" class
Remove "Formula" class from formula object in R
我使用 R 中的包 Formula
创建了一个可以更新的条件公式。
(此处描述:)
通过使用 Formula
包,我的公式对象得到两个 classes:"Formula"
和 "formula"
。不幸的是,"Formula"
class 不适用于我用于计算模型的 FENmlm
包。有没有办法删除 "Formula"
class 并保留 "formula"
class? ("Formula"
class 仅用于更新模型)
# Conditional formula
fml1 <- Formula::Formula(Petal.Width ~ Petal.Length | Species)
# Update conditional formula
fml2 <- update(fml, . ~ . + Sepal.Length)
# Class
class(fml2)
# [1] "Formula" "formula"
# Calculation
FENmlm::femlm(fml2, data = iris)
# Error in FENmlm::femlm(fml2, data = iris) :
# The argument 'fml' must be a formula.
# Try to delete "Formula" attribute
attributes(fml2)[[1]][[1]] <- NULL
# Error in attributes(fml2)[[1]][[1]] <- NULL : replacement has length zero
您可以将公式的 class 更新为 class <-
-
fml1 <- Formula::Formula(Petal.Width ~ Petal.Length | Species)
# Update conditional formula
fml2 <- update(fml1, . ~ . + Sepal.Length)
class(fml2) <- 'formula'
FENmlm::femlm(fml2, data = iris)
#ML estimation, family = Poisson, Dep. Var.: Petal.Width
#Observations: 150
#Cluster sizes: Species: 3
#Standard-errors type: Standard
# Estimate Std. Error z value Pr(>|z|)
#Petal.Length 0.150326 0.259850 0.578512 0.562919
#Sepal.Length -0.012575 0.227379 -0.055302 0.955898
#---
#Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# BIC: -147.53 Pseudo-R2: 0.19402
#Log-likelihood: 345.17 Squared Cor.: 0.94148
我使用 R 中的包 Formula
创建了一个可以更新的条件公式。
(此处描述:
通过使用 Formula
包,我的公式对象得到两个 classes:"Formula"
和 "formula"
。不幸的是,"Formula"
class 不适用于我用于计算模型的 FENmlm
包。有没有办法删除 "Formula"
class 并保留 "formula"
class? ("Formula"
class 仅用于更新模型)
# Conditional formula
fml1 <- Formula::Formula(Petal.Width ~ Petal.Length | Species)
# Update conditional formula
fml2 <- update(fml, . ~ . + Sepal.Length)
# Class
class(fml2)
# [1] "Formula" "formula"
# Calculation
FENmlm::femlm(fml2, data = iris)
# Error in FENmlm::femlm(fml2, data = iris) :
# The argument 'fml' must be a formula.
# Try to delete "Formula" attribute
attributes(fml2)[[1]][[1]] <- NULL
# Error in attributes(fml2)[[1]][[1]] <- NULL : replacement has length zero
您可以将公式的 class 更新为 class <-
-
fml1 <- Formula::Formula(Petal.Width ~ Petal.Length | Species)
# Update conditional formula
fml2 <- update(fml1, . ~ . + Sepal.Length)
class(fml2) <- 'formula'
FENmlm::femlm(fml2, data = iris)
#ML estimation, family = Poisson, Dep. Var.: Petal.Width
#Observations: 150
#Cluster sizes: Species: 3
#Standard-errors type: Standard
# Estimate Std. Error z value Pr(>|z|)
#Petal.Length 0.150326 0.259850 0.578512 0.562919
#Sepal.Length -0.012575 0.227379 -0.055302 0.955898
#---
#Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# BIC: -147.53 Pseudo-R2: 0.19402
#Log-likelihood: 345.17 Squared Cor.: 0.94148