【问题标题】:Subsetting with dredge function (MuMin)带疏通功能的子集(MuMin)
【发布时间】:2023-02-12 14:05:14
【问题描述】:

我正在尝试对从具有线性和非线性项的全局模型中挖掘出来的一系列模型进行子集化。没有相互作用,例如

Glblm <- Y ~ X1 + X2 + X3 + I(X3^2) + X4 + X5 + X6 + I(X6^2) + X7 + I(X7^2)

我想指定 X3^2 不应该在没有 X3 的情况下出现,但是 X3 可以在没有 X3^2 的情况下单独出现(对于 X6 和 X7 也是如此)。

据我从文档中了解到,我尝试了以下操作:

ssm <-dredge (Glblm, subset=(X3| !I(X3^2)) && (X6| !I(X6^2)) && (X7| !I(X7^2))) 

当我阅读https://stackoverflow.com/questions/55252019/dredge-in-mumin-r-keeps-models-with-higher-order-terms-without-their-respectiv 时,我也尝试先制作一个子集 例如

hbfsubset <- expression(  dc(X3, `I(X3^2)`) &  dc(`X6`, `I(X6^2)`)&  dc(`X7`, `I(X7^2)`))

ssm <-dredge (Glblm, subset=hbfsubset)

两者都没有生成模型的子集,而是在使用以下方法检查“ssm”时返回完整的模型列表:

model.sel(ssm)

任何帮助将不胜感激。

【问题讨论】:

    标签: r subset mumin


    【解决方案1】:

    需要您提供一个可重现的示例来查明问题,并指定您适合的模型类型。

    在简单的线性模型中(lmMuMIn 手册中提供的那些示例),拟合项的名称与您在全局模型中键入的名称完全相同,但在更复杂的模型中可能并非如此(例如glmmTMB)。

    这是一个例子:

    library(MuMIn)
    library(glmmTMB)
    
    # a simple linear model, using Cement data from MuMIn
    m1 <- lm(y ~ X1 + I(X1^2) + X2 + I(X2^2), data = Cement, na.action = "na.fail")
    
    # dredge without a subset
    d1 <- dredge(m1)
    # 16 models produced
    
    # dredge with a subset
    d1_sub <- dredge(m1, subset = dc(`X1`, `I(X1^2)`) & dc(`X2`, `I(X2^2)`))
    # 9 models produced, works totally fine
    
    
    # a glmmTMB linear model
    m2 <- glmmTMB(y ~ X1 + I(X1^2) + X2 + I(X2^2), data = Cement, na.action = "na.fail")
    
    # dredge without a subset
    d2 <- dredge(m2)
    # 16 models produced
    
    # dredge with a subset
    d2_sub <- dredge(m2, subset = dc(`X1`, `I(X1^2)`) & dc(`X2`, `I(X2^2)`))
    # 16 models produced, subset didn't work and no warning or error produced
    
    # this is because the term names of a glmmTMB object in dredge() is not the same as the typed global model anymore:
    names(d2_sub) 
    # [1] "cond((Int))"   "disp((Int))"   "cond(X1)"      "cond(I(X1^2))" "cond(X2)"      "cond(I(X2^2))" "df"            "logLik"        "AICc"         
    # [10] "delta"         "weight"   
    # e.g., now the X1 in the typed global model is actually called cond(X1)
    
    # what will work for glmmTMB:
    d2_sub <- dredge(m2, subset = dc(`cond(X1)`, `cond(I(X1^2))`) & dc(`cond(X2)`, `cond(I(X2^2))`))
    # 9 models produced
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2021-12-06
      • 2023-03-12
      相关资源
      最近更新 更多