使用來自 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)
這基本上為我選擇的每個加權變數提供了不同的錯誤訊息。這里使用權重似乎是這里唯一的問題。權重向量長度與模型中的資料相同,所以我真的不明白為什么這不起作用。任何見解表示贊賞。
uj5u.com熱心網友回復:
如果使權重總和為 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/375197.html
