在 glmmPQL 中使用权重
using weights in a glmmPQL
使用来自 SpData 的 'baltimore' 住房数据,我想将天井的存在建模为响应变量,并将房价作为解释变量。我还想按住房面积在我的模型中包含权重。
我的代码:
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)
这基本上为我选择的每个加权变量提供了不同的错误消息。这里使用权重似乎是这里唯一的问题。权重向量长度与模型中的数据相同,所以我不太明白为什么这不起作用。任何见解表示赞赏。
如果使权重总和为 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
使用来自 SpData 的 'baltimore' 住房数据,我想将天井的存在建模为响应变量,并将房价作为解释变量。我还想按住房面积在我的模型中包含权重。
我的代码:
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)
这基本上为我选择的每个加权变量提供了不同的错误消息。这里使用权重似乎是这里唯一的问题。权重向量长度与模型中的数据相同,所以我不太明白为什么这不起作用。任何见解表示赞赏。
如果使权重总和为 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