rweightednlmemass

using weights in a glmmPQL


Using the 'baltimore' housing data from SpData, I want to model the presence of a patio as the response variable, with house price as the explanatory variable. I also want to include weights in my model by housing area.

My code:

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)

This basically gives me a different error message for each weighting variable I choose. The use of weights here seem to be the only problem here. The weights vector length is the same as the data in the model, so I don't really understan why this isn't working. Any insight appreciated.


Solution

  • If you make the weights sum to 1, the model converges.

    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