美文网首页
纵向数据的分析方法之 广义估计方程

纵向数据的分析方法之 广义估计方程

作者: 灵活胖子的进步之路 | 来源:发表于2022-10-02 09:18 被阅读0次

    英文教程地址
    https://data.library.virginia.edu/getting-started-with-generalized-estimating-equations/

    广义估计方程和混合效应模型及多水平模型的区别如下

    1. The main difference is that it’s a marginal model. It seeks to model a population average. Mixed-effect/Multilevel models are subject-specific, or conditional, models. They allow us to estimate different parameters for each subject or cluster. In other words, the parameter estimates are conditional on the subject/cluster. This in turn provides insight into the variability between subjects or clusters. We can also obtain a population-level model from a mixed-effect model, but it’s basically an average of the subject-specific models.

    2. GEE is intended for simple clustering or repeated measures. It cannot easily accommodate more complex designs such as nested or crossed groups; for example, nested repeated measures within a subject or group. This is something better suited for a mixed-effect model.

    3. GEE computations are usually easier than mixed-effect model computations. GEE does not use the likelihood methods that mixed-effect models employ, which means GEE can sometimes estimate more complex models.Because GEE doesn’t use likelihood methods, the estimated “model” is incomplete and not suitable for simulation.

    4. GEE allows us to specify a correlation structure for different responses within a subject or group. For example, we can specify that the correlation of measurements taken closer together is higher than those taken farther apart. This is not something that’s currently possible in the popular lme4 package.

    #建立模拟数据集
    URL <- "http://static.lib.virginia.edu/statlab/materials/data/depression.csv"
    dat <- read.csv(URL, stringsAsFactors = TRUE)
    dat$id <- factor(dat$id)
    dat$drug <- relevel(dat$drug, ref = "standard")
    head(dat, n = 3)
    
    数据集情况
    #查看病人个数(每个病人可以有多个观测)
    dat%>%
      distinct(id)%>%
      count()
    
    总共340例患者
    #查看数据分布情况
    with(dat, tapply(depression, list(diagnose, drug, time), mean)) %>% 
      ftable() %>% 
      round(2)
    
    分组结果数据分布情况
    #构建广义估计方程并查看最终结果
    dep_gee <- gee(depression ~ diagnose + drug*time,#方程,注意交互作用
                   data = dat, #数据集
                   id = id, #患者识别编号
                   family = binomial,#连接函数
                   corstr = "independence")#数据相关矩阵,这里设定为独立
    summary(dep_gee)
    
    广义估计方程结果

    exp(estimate)后可以得到OR值,可以看到,independence的作业相关矩阵中假设组内相关性是0,因为一个id是3个观察,所以是3乘以3的矩阵了

    # Now let’s try a model with an exchangeable correlation structure. 
    # This says all pairs of responses within a subject are equally correlated. 
    # To do this we set corstr = "exchangeable".
    #设定相关性矩阵为exchangeable,意思是组内配对之间的相关性系数相等
    dep_gee2 <- gee(depression ~ diagnose + drug*time,
                    data = dat, 
                    id = id, 
                    family = binomial,
                    corstr = "exchangeable")
    summary(dep_gee2)
    
    exchangeable相关性矩阵下,除对角线外,其他相关性系数相等.png
    # Another possibility for correlation is an autoregressive structure. 
    # This allows correlations of measurements taken closer together to be higher than those taken farther apart.
    #设定自回归相关性矩阵并查看结果
    dep_gee3 <- gee(depression ~ diagnose + drug*time,
                    data = dat, 
                    id = id, 
                    family = binomial,
                    corstr = "AR-M", Mv = 1)
    
    dep_gee3$working.correlation
    
    自回归矩阵,距离较近的点的相关性系数大于距离远的点

    作业相关矩阵的选择

    How to choose which correlation structure to use? The good news is GEE estimates are valid even if you misspecify the correlation structure (Agresti, 2002). Of course this assumes the model is correct, but then again no model is exactly correct. Agresti suggests using the exchangeable structure as a start and then checking how the coefficient estimates and standard errors change with other correlation structures. If the changes are minimal, go with the simpler correlation structure.

    相关文章

      网友评论

          本文标题:纵向数据的分析方法之 广义估计方程

          本文链接:https://www.haomeiwen.com/subject/pxzdartx.html