代码之家  ›  专栏  ›  技术社区  ›  Eric Fail

基于估计和st.误差的绘图回归估计

  •  0
  • Eric Fail  · 技术社区  · 7 年前

    我正在和 https://strengejacke.github.io/sjPlot/ 并享受可视化和比较如下估计的可能性(参见下面的工作示例)。我想知道是否有可能,在 ,可能n ,仅根据估计值和标准误差绘制结果?假设我在一篇论文中看到一个模型,我估计了我自己的模型,现在我想将我的模型与论文中的模型进行比较,我只有估计和标准误差。我在上面看到的 SO 但是这也有点基于模型。

    任何反馈或建议将不胜感激。

    # install.packages(c("sjmisc","sjPlot"), dependencies = TRUE)
    # prepare data
    library(sjmisc)
    data(efc)
    efc <- to_factor(efc, c161sex, e42dep, c172code)
    m <- lm(neg_c_7 ~ pos_v_4 + c12hour + e42dep + c172code, data = efc)
    
    # simple forest plot
    library(sjPlot)
    plot_model(m)
    

    sjksj

    我想一个初步的预期结果会有点像这样,

    gdfgdf

    我刚碰到 https://cran.r-project.org/web/packages/coefplot/ 但我在一台没有R的机器上,我知道,奇怪,但我会调查 尽快。也许那是一条可能的路线。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Indrajeet Patil    7 年前

    你可以很容易地用 dotwhisker 包裹。默认情况下,包将95%的CI显示为触须,但您可以修改作为输入输入的数据帧来更改它。

    # Package preload
    library(dotwhisker)
    library(broom)
    library(dplyr)
    
    # run a regression compatible with tidy
    m1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
    
    # regression compatible with tidy
    m1_df <- broom::tidy(x = m1) # create data.frame of regression results
    m1_df # a tidy data.frame available for dwplot
    #> # A tibble: 5 x 5
    #>   term         estimate std.error statistic       p.value
    #>   <chr>           <dbl>     <dbl>     <dbl>         <dbl>
    #> 1 (Intercept)  43.5        4.86       8.96  0.00000000142
    #> 2 wt           -3.79       1.08      -3.51  0.00161      
    #> 3 cyl          -1.78       0.614     -2.91  0.00722      
    #> 4 disp          0.00694    0.0120     0.578 0.568        
    #> 5 gear         -0.490      0.790     -0.621 0.540
    
    # create  new columns for upper and lower bounds
    m1_df <- m1_df %>%
      dplyr::mutate(
        .data = .,
        conf.low = estimate - std.error,
        conf.high = estimate + std.error
      )
    
    # creating the dot and whisker plot
    # note that whiskers correspond to standard error and not 95% CI
    dotwhisker::dw_plot(m1_df)
    

    您还可以看到小插曲中的示例,这些小插曲显示了如何修改此基本绘图,特别是如果要比较不同模型之间的结果: https://cran.r-project.org/web/packages/dotwhisker/vignettes/kl2007_examples.html

    例如: enter image description here

    推荐文章