0

使用来自 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)

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

4

1 回答 1

0

如果您使权重总和为 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 
于 2021-12-06T14:37:09.150 回答