首页 文章

绘制使用bbmle包创建的非线性模型的残差

提问于
浏览
0

我正在尝试获取用bbmle构建的非线性模型的残差图,但不知道如何处理此任务 . bble包中有一些关于残差的注释,但没有办法绘制像直方图这样的东西 . 任何帮助将不胜感激

1 回答

  • 2

    residuals()函数似乎有效 . 然后你可以随心所欲 - 直方图,qqplot,残差的散点图与预测值(predict()也有一个方法) . 例如:

    set.seed(1002)
    lymax <- c(0,2)
    lhalf <- 0
    x <- runif(200)
    g <- factor(rep(c("a","b"),each=100))
    y <- rnbinom(200,mu=exp(lymax[g])/(1+x/exp(lhalf)),size=2)
    dat <- data.frame(y,g,x)
    
    fit3 <- mle2(y~dnbinom(mu=exp(lymax)/(1+x/exp(lhalf)),size=exp(logk)),
        parameters=list(lymax~g),
        start=list(lymax=0,lhalf=0,logk=0),
        data=dat)
    
    
    par(mfrow=c(2,2))
    hist(residuals(fit3))
    qqnorm(residuals(fit3))
    hist(residuals(fit3, type="response"))
    qqnorm(residuals(fit3, type="response"))
    

    enter image description here

    或者我错过了这一点?

相关问题