首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于逐步公式的GLM和GLMM的_R_码

基于逐步公式的GLM和GLMM的_R_码
EN

Stack Overflow用户
提问于 2011-08-03 16:32:45
回答 2查看 3.2K关注 0票数 1

我知道如何将广义线性模型(GLMs)和广义线性混合模型(GLMs)与lme4软件包中的glmglmer进行拟合。作为统计学专业的学生,我有兴趣学习如何拟合GLMGLMME 29以下逐级公式基R码。如果你能指出这方面的任何资源和/或参考,我将不胜感激。提前谢谢。

EDiT

我想用公式一步一步地做、GLM、和GLMM,就像我们用矩阵方法做LM一样。是否有使用这种方法的R书或教程?谢谢

EN

回答 2

Stack Overflow用户

发布于 2011-08-03 22:43:37

Fox和Weisberg的“应用回归的R伙伴”在第8章有一个很好的指南,并以logistic回归为例。本书还介绍了如何使用S3和S4对象创建模型函数。特别是,它很好地回答了我最近提出的一个关于建模的问题-- What are the key components and functions for standard model objects in R?

票数 2
EN

Stack Overflow用户

发布于 2013-01-31 04:49:16

这可能对有帮助

** Poisson回归: GLM**

*建议阅读:广义线性模型导论,Annette J. Dobson著,第2版,第4章,第4.3和4.4节*

代码语言:javascript
复制
library(MASS)
poisreg = function(n, b1, y, x1, tolerence) {  # n is the number of iteration   
  x0 = rep(1, length(x1))   
  x = cbind(x0, x1)  
  y = as.matrix(y)  
  w = matrix(0, nrow = (length(y)), ncol = (length(y)))  
  b0 = b1  
  result = b0
  for (i in 1:n) {  
    mu = exp(x %*% b0)     
    diag(w) = mu  
    eta = x %*% b0  
    z = eta + (y - mu) * (1/mu)   # dot product of (y - mu) & (1/mu)   
    xtwx = t(x) %*% w %*% x  
    xtwz = t(x) %*% w %*% z  
    b1 = solve(xtwx, xtwz)  
    if(sqrt(sum(b0 - b1)^2) > tolerence) (b0 <- b1)  
    result<- cbind(result,b1) # to get all the iterated values  
  }  
  result  
}
x1 <- c(-1,-1,0,0,0,0,1,1,1) # x1 is the explanatory variable 
y<- c(2,3,6,7,8,9,10,12,15)  # y is the dependent variable
b1 = c(1,2) # initial value  
poisreg (10, b1, y, x1, .001)   # Nicely converge after 10 iterations  
glm(y~x1, family=poisson(link="log"))   # check your result with the R GLM program
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6929909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档