以下R代码产生:
> source("s.R")
[1] "unweighted"
[1] "model: linear, r.squared: 0.949843"
[1] "model: beta logit, pseudo.r.squared: 0.956150"
[1] "model: beta loglog, pseudo.r.squared: 0.891941"
[1] "weighted"
[1] "model: linear, r.squared: 0.950847"
[1] "model: beta logit, pseudo.r.squared: 0.956150"
[1] "model: beta loglog, pseudo.r.squared: 0.891941"
Warning messages:
1: In betareg.fit(X, Y, Z, weights, offset, link, link.phi, type, control) :
no valid starting value for precision parameter found, using 1 instead
2: In betareg.fit(X, Y, Z, weights, offset, link, link.phi, type, control) :
no valid starting value for precision parameter found, using 1 instead
>
betreg的相关值对于加权和未加权都是相同的。这合理吗?还是我有错误?
还有,警告消息试图告诉我什么?
相关的question。
printOneSummary<-function(label,model) {
if(is(model,"lm")) print(sprintf("model: %s, r.squared: %f",label,summary(model)$r.squared))
else print(sprintf("model: %s, pseudo.r.squared: %f",label,summary(model)$pseudo.r.squared))
}
printSummary<-function(models) {
for(i in 1:length(models))
printOneSummary(modelLabels[i],models[[i]])
}
makeModels<-function(x,y,weights,weighted){
models <-NULL
if(weighted) {
print("weighted")
m<-lm(y~x,na.action=na.omit,weights=weights)
logit<-betareg(y~x,na.action=na.omit,weights=weights)
loglog <- betareg(y~x,na.action=na.omit,weights=weights,link = "loglog")
models<-list(m,logit,loglog)
} else {
print("unweighted")
m<-lm(y~x,na.action=na.omit)
logit<-betareg(y~x,na.action=na.omit)
loglog<-betareg(y~x,na.action=na.omit,link="loglog")
models<-list(m,logit,loglog)
}
}
if(!require(betareg)){install.packages("betareg")}
set.seed(123)
modelLabels<-c("linear","beta logit","beta loglog")
x=seq(100,200,length.out=60)
y=1-(.1+.8*sqrt((x-100)/100))
df<-data.frame(x,y)
df$n<-runif(length(x),1,10)
df$size<-df$n/sum(df$n)
models<-makeModels(df$x,df$y,df$size,F)
printSummary(models)
models<-makeModels(df$x,df$y,df$size,T)
printSummary(models)
答案 0 :(得分:0)
感谢您发现这一点!这确实是betareg()
中的错误,到目前为止,该错误已完全忽略了weights
参数。我刚刚在R-Forge的开发版本中对其进行了修复:https://R-Forge.R-project.org/R/?group_id=1220