代码之家  ›  专栏  ›  技术社区  ›  Ray Tayek

为什么β重测中的加权相关性和非加权相关性没有区别?

  •  0
  • Ray Tayek  · 技术社区  · 6 年前

    下面的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
    > 
    

    还有,警告信息想告诉我什么?

    相关的 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)
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Achim Zeileis    6 年前

    谢谢你发现这个!这确实是一个错误 betareg() 到目前为止完全忽略了 weights https://R-Forge.R-project.org/R/?group_id=1220