0

我使用FormulaR 中的包来创建一个可以更新的条件公式。

(此处描述:如何更新条件公式?

通过使用该Formula包,我的公式对象获得了两个类:"Formula""formula". 不幸的是,"Formula"该类不适FENmlm用于我用于计算模型的包。有没有办法删除"Formula"课程并保留"formula"课程?("Formula"该类仅用于更新模型)

# 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
4

1 回答 1

1

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 
于 2021-07-30T10:13:56.290 回答