【问题标题】:using weights in a glmmPQL在 glmmPQL 中使用权重
【发布时间】:2022-01-11 18:14:38
【问题描述】:

使用来自 SpData 的“巴尔的摩”住房数据,我想将庭院的存在建模为响应变量,并将房价作为解释变量。我还想在我的模型中按住房面积包括权重。

我的代码:

library(spData)
library(nlme)
library(dplyr)
library(MASS)

baltimore<-spData::baltimore
baltimore$logpr = log(baltimore$PRICE)

#alright, i want this to be weighted by sqft
w=baltimore$SQFT/100
w

model1 <- glmmPQL(PATIO ~ PRICE  , random = ~1|CITCOU, data = baltimore,family=binomial,correlation = corExp(form = ~X + Y, nugget = T),weights = w)

这基本上为我选择的每个加权变量提供了不同的错误消息。这里使用权重似乎是这里唯一的问题。权重向量长度与模型中的数据相同,所以我真的不明白为什么这不起作用。任何见解都值得赞赏。

【问题讨论】:

    标签: r weighted nlme mass


    【解决方案1】:

    如果使权重总和为 1,则模型收敛。

    w <- w/sum(w)
    
    model1 <- glmmPQL(PATIO ~ PRICE  , 
                      random = ~1|CITCOU, 
                      data = baltimore,
                      family=binomial,
                      correlation = corExp(form = ~X + Y, nugget = T), 
                      weights = w)
    
    summary(model1)
    
    # Linear mixed-effects model fit by maximum likelihood
    # Data: baltimore 
    # AIC BIC logLik
    # NA  NA     NA
    # 
    # Random effects:
    #   Formula: ~1 | CITCOU
    # (Intercept)   Residual
    # StdDev: 0.001372962 0.06760035
    # 
    # Correlation Structure: Exponential spatial correlation
    # Formula: ~X + Y | CITCOU 
    # Parameter estimate(s):
    #   range     nugget 
    # 0.03104283 0.11152655 
    # Variance function:
    #   Structure: fixed weights
    # Formula: ~invwt 
    # Fixed effects:  PATIO ~ PRICE 
    #                 Value Std.Error  DF   t-value p-value
    # (Intercept) -4.343533 0.5705149 208 -7.613355       0
    # PRICE        0.053687 0.0092687 208  5.792323       0
    # Correlation: 
    #   (Intr)
    # PRICE -0.937
    # 
    # Standardized Within-Group Residuals:
    #        Min         Q1        Med         Q3        Max 
    # -2.8915877 -0.3851644 -0.2667641 -0.1707177  5.9131663 
    # 
    # Number of Observations: 211
    # Number of Groups: 2 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-21
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      相关资源
      最近更新 更多