Coder Social home page Coder Social logo

broom.mixed's People

Contributors

andrewheiss avatar bbolker avatar billdenney avatar corybrunson avatar dmenne avatar eduardszoecs avatar joe-wasserman avatar matthieu-bruneaux avatar romainfrancois avatar strengejacke avatar vincentarelbundock avatar wpetry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

broom.mixed's Issues

Re-export tidy, glance, augment

broom.mixed should re-export tidy/glance/augment so that users do not need to load broom to use broom.mixed.

There's a vignette incoming with recommendations on how to do this, but it's a week or two out at the moment. Just want you to be aware until then.

library(broom.mixed)
tidy()
#> Error in tidy(): could not find function "tidy"

Created on 2018-07-23 by the reprex package (v0.2.0).

library 'lme4' not found

I am trying to run a mixed model using lmerTest for which I needed to install lme4 but R is not recognizing the package.

install.packages("lme4")
Installing package into ‘C:/Users/nd911/OneDrive/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/lme4_1.1-17.zip'
Content type 'application/zip' length 5229366 bytes (5.0 MB)
downloaded 5.0 MB

package ‘lme4’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘lme4’

The downloaded binary packages are in
C:\Users\nd911\AppData\Local\Temp\Rtmp6bYGvh\downloaded_packages

library(lme4)
Error in library(lme4) : there is no package called ‘lme4’

Here is a little more info about my session:

options(repos="https://cran.rstudio.com")
a1 <- available.packages()
a1[a1[,"Package"]=="nlme",]
Package Version Priority Depends
"nlme" "3.1-137" "recommended" "R (>= 3.4.0)"
Imports LinkingTo Suggests Enhances
"graphics, stats, utils, lattice" NA "Hmisc, MASS" NA
License License_is_FOSS License_restricts_use OS_type
"GPL (>= 2) | file LICENCE" NA NA NA
Archs MD5sum NeedsCompilation File
NA NA "yes" NA
Repository
"https://cran.rstudio.com/src/contrib"
sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.4.4 tools_3.4.4 yaml_2.1.14

R --vanilla
Error: object 'R' not found
sessionInfo() ## see if you have a clean session (your session above isn't clean, it has non-default
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

loaded via a namespace (and not attached):
[1] compiler_3.4.4 rsconnect_0.8.5 tools_3.4.4 yaml_2.1.14

packages loaded)

packageVersion("nlme")
[1] ‘3.1.137’
sapply(.libPaths(),packageVersion,pkg="nlme") ## see if you have multiple versions installed
$C:/Users/abc/OneDrive/Documents/R/win-library/3.4
[1] 3 1 137

$C:/Program Files/R/R-3.4.4/library
[1] 3 1 131 1

require("lme4")
Loading required package: lme4
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘lme4’

improve random effect reporting (specifically for lme4)

imported from comment here:

library(broom)
library(broom.mixed)
library(lme4)
m <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
tidy(m,effects="ran_pars") ## sd, cor
tidy(m,effects="ran_modes") ## gives *coefficients* (non-zero-centered, coef()) rather than offsets (ranef()) ?
tidy(m, effects="coefs")
## Error in seq_len(nrow(x)) :   argument must be coercible to non-negative integer

The terminology used by lme4 is that ranef() returns "conditional modes" and coef()

Computes the sum of the random and fixed effects coefficients for each explanatory variable for each level of each grouping factor.

CRAN submission soon?

Some of my package functions rely on broom tidiers for mixed-effects models and since the last release of broom they print warnings about these deprecated functions. This means that all these warnings will also shows up for my R CMD CHECK and I'd like to avoid that. So it will be better for me to switch to broom.mixed before releasing any new versions on CRAN.

Are there plans to submit broom.mixed to CRAN any time soon? I'd like to have a rough timeline in mind for my own package releases accordingly. Thanks.

support gls

Dear Ben

Many thanks for this very useful extension to broom

Would it possible to make the gls object work with broom.mixed? As you have already get this working with (n)lme?

The reason I am asking with this is here:

amices/mice#105

In short, the mice author decided to start using broom in one of his key function (pool) so we cannot use gls objects (and many others) with the mice package.

It would be wonderful if you could add gls objects to your broom.mixed.

Best wishes,

Shinichi

augment should produce tibbles for internal consistency

To be internally consistent, augment method should output tibbles-

# setup
set.seed(123)
library(lme4)
#> Loading required package: Matrix
library(broom.mixed)
#> Registered S3 methods overwritten by 'broom.mixed':
#>   method         from 
#>   augment.lme    broom
#>   augment.merMod broom
#>   glance.lme     broom
#>   glance.merMod  broom
#>   glance.stanreg broom
#>   tidy.brmsfit   broom
#>   tidy.gamlss    broom
#>   tidy.lme       broom
#>   tidy.merMod    broom
#>   tidy.rjags     broom
#>   tidy.stanfit   broom
#>   tidy.stanreg   broom

# model
mod <- lme4::lmer(
  formula = Reaction ~ Days + (Days | Subject),
  data = sleepstudy
)

# tidy -> tibble
broom.mixed::tidy(mod)
#> # A tibble: 6 x 6
#>   effect   group    term                  estimate std.error statistic
#>   <chr>    <chr>    <chr>                    <dbl>     <dbl>     <dbl>
#> 1 fixed    <NA>     (Intercept)           251.          6.82     36.8 
#> 2 fixed    <NA>     Days                   10.5         1.55      6.77
#> 3 ran_pars Subject  sd__(Intercept)        24.7        NA        NA   
#> 4 ran_pars Subject  sd__Days                5.92       NA        NA   
#> 5 ran_pars Subject  cor__(Intercept).Days   0.0656     NA        NA   
#> 6 ran_pars Residual sd__Observation        25.6        NA        NA

# glance -> tibble
broom.mixed::glance(mod)
#> # A tibble: 1 x 6
#>   sigma logLik   AIC   BIC REMLcrit df.residual
#>   <dbl>  <dbl> <dbl> <dbl>    <dbl>       <int>
#> 1  25.6  -872. 1756. 1775.    1744.         174

# augment -> data.frame
broom.mixed::augment(mod)
#>     Reaction Days Subject  .fitted       .resid       .hat      .cooksd
#> 1   249.5600    0     308 253.6637   -4.1036702 0.22930300 4.963124e-03
#> 2   258.7047    1     308 273.3299  -14.6252281 0.16972925 4.020595e-02
#> 3   250.8006    2     308 292.9962  -42.1955860 0.12682322 2.260978e-01
#> 4   321.4398    3     308 312.6624    8.7773561 0.10058490 7.313204e-03
#> 5   356.8519    4     308 332.3287   24.5231982 0.09101429 5.057286e-02
#> 6   414.6901    5     308 351.9950   62.6951403 0.09811140 3.619506e-01
#> 7   382.2038    6     308 371.6612   10.5425825 0.12187623 1.341125e-02
#> 8   290.1486    7     308 391.3275 -101.1788754 0.16230877 1.807680e+00
#> 9   430.5853    8     308 410.9937   19.5915667 0.21940902 1.055148e-01
#> 10  466.3535    9     308 430.6600   35.6935088 0.29317698 5.707617e-01
#> 11  222.7339    0     309 211.0065   11.7273720 0.22930300 4.053327e-02
#> 12  205.2658    1     309 212.8541   -7.5883108 0.16972925 1.082369e-02
#> 13  202.9778    2     309 214.7017  -11.7238935 0.12682322 1.745444e-02
#> 14  204.7070    3     309 216.5493  -11.8422763 0.10058490 1.331222e-02
#> 15  207.7161    4     309 218.3969  -10.6807591 0.09101429 9.593289e-03
#> 16  215.9618    5     309 220.2444   -4.2826418 0.09811140 1.688904e-03
#> 17  213.6303    6     309 222.0920   -8.4617246 0.12187623 8.639589e-03
#> 18  217.7272    7     309 223.9396   -6.2124074 0.16230877 6.814934e-03
#> 19  224.2957    8     309 225.7872   -1.4914901 0.21940902 6.115275e-04
#> 20  237.3142    9     309 227.6348    9.6794271 0.29317698 4.197354e-02
#> 21  199.0539    0     310 212.4449  -13.3909591 0.22930300 5.284861e-02
#> 22  194.3322    1     310 217.4633  -23.1310651 0.16972925 1.005718e-01
#> 23  234.3200    2     310 222.4817   11.8383288 0.12682322 1.779684e-02
#> 24  232.8416    3     310 227.5001    5.3415228 0.10058490 2.708385e-03
#> 25  229.3074    4     310 232.5185   -3.2110832 0.09101429 8.670945e-04
#> 26  220.4579    5     310 237.5369  -17.0789893 0.09811140 2.685999e-02
#> 27  235.4208    6     310 242.5553   -7.1344953 0.12187623 6.141887e-03
#> 28  255.7511    7     310 247.5737    8.1773986 0.16230877 1.180789e-02
#> 29  261.0125    8     310 252.5921    8.4203926 0.21940902 1.949126e-02
#> 30  247.5153    9     310 257.6105  -10.0952135 0.29317698 4.565699e-02
#> 31  321.5426    0     330 275.0956   46.4469967 0.22930300 6.358072e-01
#> 32  300.4002    1     330 280.7486   19.6516420 0.16972925 7.259099e-02
#> 33  283.8565    2     330 286.4015   -2.5450126 0.12682322 8.225117e-04
#> 34  285.1330    3     330 292.0545   -6.9214673 0.10058490 4.547540e-03
#> 35  285.7973    4     330 297.7074  -11.9101219 0.09101429 1.192877e-02
#> 36  297.5855    5     330 303.3604   -5.7748766 0.09811140 3.070909e-03
#> 37  280.2396    6     330 309.0133  -28.7737313 0.12187623 9.990051e-02
#> 38  318.2613    7     330 314.6663    3.5950141 0.16230877 2.282144e-03
#> 39  305.3495    8     330 320.3192  -14.9697406 0.21940902 6.160327e-02
#> 40  354.0487    9     330 325.9722   28.0765048 0.29317698 3.531526e-01
#> 41  287.6079    0     331 273.6653   13.9425924 0.22930300 5.729243e-02
#> 42  285.0000    1     331 281.0627    3.9373011 0.16972925 2.913951e-03
#> 43  301.8206    2     331 288.4601   13.3605097 0.12682322 2.266774e-02
#> 44  320.1153    3     331 295.8575   24.2578183 0.10058490 5.585779e-02
#> 45  316.2773    4     331 303.2549   13.0224270 0.09101429 1.426091e-02
#> 46  293.3187    5     331 310.6523  -17.3335644 0.09811140 2.766669e-02
#> 47  290.0750    6     331 318.0497  -27.9746558 0.12187623 9.442888e-02
#> 48  334.8177    7     331 325.4470    9.3706529 0.16230877 1.550535e-02
#> 49  293.7469    8     331 332.8444  -39.0975385 0.21940902 4.202174e-01
#> 50  371.5811    9     331 340.2418   31.3392701 0.29317698 4.400014e-01
#> 51  234.8606    0     332 260.4446  -25.5840308 0.22930300 1.929071e-01
#> 52  242.8118    1     332 270.6397  -27.8279461 0.16972925 1.455618e-01
#> 53  272.9613    2     332 280.8349   -7.8735614 0.12682322 7.872354e-03
#> 54  309.7688    3     332 291.0300   18.7388233 0.10058490 3.333227e-02
#> 55  317.4629    4     332 301.2251   16.2378080 0.09101429 2.217268e-02
#> 56  309.9976    5     332 311.4202   -1.4226073 0.09811140 1.863595e-04
#> 57  454.1619    6     332 321.6153  132.5465774 0.12187623 2.119885e+00
#> 58  346.8311    7     332 331.8104   15.0206621 0.16230877 3.984006e-02
#> 59  330.3003    8     332 342.0056  -11.7052532 0.21940902 3.766490e-02
#> 60  253.8644    9     332 352.2007  -98.3362685 0.29317698 4.332153e+00
#> 61  283.8424    0     333 268.2455   15.5968640 0.22930300 7.169432e-02
#> 62  289.5550    1     333 278.4892   11.0658025 0.16972925 2.301711e-02
#> 63  276.7693    2     333 288.7329  -11.9635590 0.12682322 1.817536e-02
#> 64  299.8097    3     333 298.9765    0.8331794 0.10058490 6.589574e-05
#> 65  297.1710    4     333 309.2202  -12.0491821 0.09101429 1.220895e-02
#> 66  338.1665    5     333 319.4638   18.7026564 0.09811140 3.220980e-02
#> 67  332.0265    6     333 329.7075    2.3189949 0.12187623 6.488957e-04
#> 68  348.8399    7     333 339.9512    8.8887334 0.16230877 1.395152e-02
#> 69  333.3600    8     333 350.1948  -16.8348282 0.21940902 7.790989e-02
#> 70  362.0428    9     333 360.4385    1.6043103 0.29317698 1.153063e-03
#> 71  265.4731    0     334 244.1725   21.3005743 0.22930300 1.337189e-01
#> 72  276.2012    1     334 255.7144   20.4868123 0.16972925 7.889215e-02
#> 73  243.3647    2     334 267.2562  -23.8915497 0.12682322 7.248545e-02
#> 74  254.6723    3     334 278.7981  -24.1258118 0.10058490 5.525150e-02
#> 75  279.0244    4     334 290.3400  -11.3155738 0.09101429 1.076754e-02
#> 76  284.1912    5     334 301.8818  -17.6906358 0.09811140 2.881830e-02
#> 77  305.5248    6     334 313.4237   -7.8988979 0.12187623 7.528498e-03
#> 78  331.5229    7     334 324.9656    6.5573401 0.16230877 7.592718e-03
#> 79  335.7469    8     334 336.5074   -0.7605219 0.21940902 1.590006e-04
#> 80  377.2990    9     334 348.0493   29.2497160 0.29317698 3.832830e-01
#> 81  241.6083    0     335 251.0714   -9.4631090 0.22930300 2.639234e-02
#> 82  273.9472    1     335 250.7865   23.1606641 0.16972925 1.008294e-01
#> 83  254.4907    2     335 250.5017    3.9890373 0.12682322 2.020684e-03
#> 84  270.8021    3     335 250.2168   20.5853104 0.10058490 4.022491e-02
#> 85  251.4519    4     335 249.9319    1.5199836 0.09101429 1.942858e-04
#> 86  254.6362    5     335 249.6470    4.9891567 0.09811140 2.292112e-03
#> 87  245.4523    6     335 249.3622   -3.9098701 0.12187623 1.844591e-03
#> 88  235.3110    7     335 249.0773  -13.7662970 0.16230877 3.346386e-02
#> 89  235.7541    8     335 248.7924  -13.0383238 0.21940902 4.673247e-02
#> 90  237.2466    9     335 248.5076  -11.2609507 0.29317698 5.681021e-02
#> 91  312.3666    0     337 286.2955   26.0711444 0.22930300 2.003228e-01
#> 92  313.8058    1     337 305.3910    8.4147745 0.16972925 1.330975e-02
#> 93  291.6112    2     337 324.4866  -32.8753955 0.12682322 1.372474e-01
#> 94  346.1222    3     337 343.5822    2.5400346 0.10058490 6.124343e-04
#> 95  365.7324    4     337 362.6777    3.0546647 0.09101429 7.846760e-04
#> 96  391.8385    5     337 381.7733   10.0651948 0.09811140 9.328802e-03
#> 97  404.2601    6     337 400.8689    3.3912248 0.12187623 1.387677e-03
#> 98  416.6923    7     337 419.9644   -3.2721451 0.16230877 1.890632e-03
#> 99  455.8643    8     337 439.0600   16.8042850 0.21940902 7.762744e-02
#> 100 458.9167    9     337 458.1556    0.7611151 0.29317698 2.595237e-04
#> 101 236.1032    0     349 226.1950    9.9082055 0.22930300 2.893345e-02
#> 102 230.3167    1     349 237.8357   -7.5189947 0.16972925 1.062685e-02
#> 103 238.9256    2     349 249.4764  -10.5507949 0.12682322 1.413620e-02
#> 104 254.9220    3     349 261.1171   -6.1950951 0.10058490 3.643143e-03
#> 105 250.7103    4     349 272.7578  -22.0474953 0.09101429 4.087726e-02
#> 106 269.7744    5     349 284.3985  -14.6240955 0.09811140 1.969335e-02
#> 107 281.5648    6     349 296.0392  -14.4743957 0.12187623 2.527995e-02
#> 108 308.1020    7     349 307.6799    0.4221041 0.16230877 3.146161e-05
#> 109 336.2806    8     349 319.3206   16.9600039 0.21940902 7.907280e-02
#> 110 351.6451    9     349 330.9613   20.6838037 0.29317698 1.916625e-01
#> 111 256.2968    0     350 238.3351   17.9616519 0.22930300 9.508297e-02
#> 112 243.4543    1     350 255.4166  -11.9623391 0.16972925 2.689783e-02
#> 113 256.2046    2     350 272.4981  -16.2935301 0.12682322 3.371263e-02
#> 114 255.5271    3     350 289.5796  -34.0525210 0.10058490 1.100725e-01
#> 115 268.9165    4     350 306.6611  -37.7446120 0.09101429 1.198045e-01
#> 116 329.7247    5     350 323.7426    5.9820971 0.09811140 3.295250e-03
#> 117 379.4445    6     350 340.8241   38.6204061 0.12187623 1.799737e-01
#> 118 362.9184    7     350 357.9056    5.0128151 0.16230877 4.437161e-03
#> 119 394.4872    8     350 374.9871   19.5001242 0.21940902 1.045322e-01
#> 120 389.0527    9     350 392.0686   -3.0158668 0.29317698 4.074747e-03
#> 121 250.5265    0     351 255.9829   -5.4564400 0.22930300 8.774633e-03
#> 122 300.0576    1     351 263.4350   36.6226312 0.16972925 2.521065e-01
#> 123 269.8939    2     351 270.8870   -0.9930976 0.12682322 1.252409e-04
#> 124 280.5891    3     351 278.3390    2.2500737 0.10058490 4.805889e-04
#> 125 271.8274    4     351 285.7911  -13.9636551 0.09101429 1.639689e-02
#> 126 304.6336    5     351 293.2431   11.3905161 0.09811140 1.194726e-02
#> 127 287.7466    6     351 300.6951  -12.9485127 0.12187623 2.023090e-02
#> 128 266.5955    7     351 308.1471  -41.5516414 0.16230877 3.048725e-01
#> 129 321.5418    8     351 315.5992    5.9426298 0.21940902 9.708062e-03
#> 130 347.5655    9     351 323.0512   24.5143010 0.29317698 2.692250e-01
#> 131 221.6771    0     352 272.2687  -50.5915973 0.22930300 7.543397e-01
#> 132 298.1939    1     352 286.2720   11.9219034 0.16972925 2.671629e-02
#> 133 326.8785    2     352 300.2753   26.6032041 0.12682322 8.987318e-02
#> 134 346.8555    3     352 314.2786   32.5769049 0.10058490 1.007395e-01
#> 135 348.7402    4     352 328.2819   20.4583056 0.09101429 3.519675e-02
#> 136 352.8287    5     352 342.2852   10.5435063 0.09811140 1.023650e-02
#> 137 354.4266    6     352 356.2885   -1.8618930 0.12187623 4.182970e-04
#> 138 360.4326    7     352 370.2918   -9.8591922 0.16230877 1.716424e-02
#> 139 375.6406    8     352 384.2951   -8.6544915 0.21940902 2.059009e-02
#> 140 388.5417    9     352 398.2984   -9.7566908 0.29317698 4.264630e-02
#> 141 271.9235    0     369 254.6806   17.2429421 0.22930300 8.762599e-02
#> 142 268.4369    1     369 266.0201    2.4168396 0.16972925 1.097945e-03
#> 143 257.2424    2     369 277.3596  -20.1171630 0.12682322 5.139202e-02
#> 144 277.6566    3     369 288.6991  -11.0424655 0.10058490 1.157477e-02
#> 145 314.8222    4     369 300.0386   14.7836319 0.09101429 1.837916e-02
#> 146 317.2135    5     369 311.3781    5.8354293 0.09811140 3.135647e-03
#> 147 298.1353    6     369 322.7176  -24.5822732 0.12187623 7.291543e-02
#> 148 348.1229    7     369 334.0571   14.0658242 0.16230877 3.493592e-02
#> 149 340.2800    8     369 345.3966   -5.1165784 0.21940902 7.196718e-03
#> 150 366.5131    9     369 356.7361    9.7770191 0.29317698 4.282420e-02
#> 151 225.2640    0     370 225.7922   -0.5282354 0.22930300 8.223662e-05
#> 152 234.5235    1     370 241.0820   -6.5584860 0.16972925 8.085227e-03
#> 153 238.9008    2     370 256.3717  -17.4709366 0.12682322 3.876096e-02
#> 154 240.4730    3     370 271.6615  -31.1884872 0.10058490 9.233553e-02
#> 155 267.5373    4     370 286.9512  -19.4139377 0.09101429 3.169499e-02
#> 156 344.1937    5     370 302.2410   41.9527117 0.09811140 1.620696e-01
#> 157 281.1481    6     370 317.5307  -36.3826389 0.12187623 1.597216e-01
#> 158 347.5855    7     370 332.8205   14.7650105 0.16230877 3.849545e-02
#> 159 365.1630    8     370 348.1102   17.0527600 0.21940902 7.994008e-02
#> 160 372.2288    9     370 363.4000    8.8288094 0.29317698 3.492051e-02
#> 161 269.8804    0     371 252.2121   17.6682554 0.22930300 9.200205e-02
#> 162 272.4428    1     371 261.6913   10.7515245 0.16972925 2.172827e-02
#> 163 277.8989    2     371 271.1704    6.7284937 0.12682322 5.749074e-03
#> 164 281.7895    3     371 280.6495    1.1399628 0.10058490 1.233564e-04
#> 165 279.1705    4     371 290.1287  -10.9581681 0.09101429 1.009809e-02
#> 166 284.5120    5     371 299.6078  -15.0957989 0.09811140 2.098426e-02
#> 167 259.2658    6     371 309.0869  -49.8211298 0.12187623 2.995039e-01
#> 168 304.6306    7     371 318.5661  -13.9354607 0.16230877 3.429134e-02
#> 169 350.7807    8     371 328.0452   22.7355085 0.21940902 1.420969e-01
#> 170 369.4692    9     371 337.5243   31.9448776 0.29317698 4.571711e-01
#> 171 269.4117    0     372 263.7196    5.6920558 0.22930300 9.548793e-03
#> 172 273.4740    1     372 275.4710   -1.9969599 0.16972925 7.495899e-04
#> 173 297.5968    2     372 287.2223   10.3745244 0.12682322 1.366780e-02
#> 174 310.6316    3     372 298.9736   11.6580087 0.10058490 1.290117e-02
#> 175 287.1726    4     372 310.7249  -23.5523070 0.09101429 4.664770e-02
#> 176 329.6076    5     372 322.4762    7.1313773 0.09811140 4.683045e-03
#> 177 334.4818    6     372 334.2275    0.2542616 0.12187623 7.800758e-06
#> 178 343.2199    7     372 345.9789   -2.7589541 0.16230877 1.344098e-03
#> 179 369.1417    8     372 357.7302   11.4115302 0.21940902 3.579835e-02
#> 180 364.1236    9     372 369.4815   -5.3578855 0.29317698 1.286066e-02
#>       .fixed      .mu .offset .sqrtXwt .sqrtrwt .weights       .wtres
#> 1   251.4051 253.6637       0        1        1        1   -4.1036702
#> 2   261.8724 273.3299       0        1        1        1  -14.6252281
#> 3   272.3397 292.9962       0        1        1        1  -42.1955860
#> 4   282.8070 312.6624       0        1        1        1    8.7773561
#> 5   293.2742 332.3287       0        1        1        1   24.5231982
#> 6   303.7415 351.9950       0        1        1        1   62.6951403
#> 7   314.2088 371.6612       0        1        1        1   10.5425825
#> 8   324.6761 391.3275       0        1        1        1 -101.1788754
#> 9   335.1434 410.9937       0        1        1        1   19.5915667
#> 10  345.6107 430.6600       0        1        1        1   35.6935088
#> 11  251.4051 211.0065       0        1        1        1   11.7273720
#> 12  261.8724 212.8541       0        1        1        1   -7.5883108
#> 13  272.3397 214.7017       0        1        1        1  -11.7238935
#> 14  282.8070 216.5493       0        1        1        1  -11.8422763
#> 15  293.2742 218.3969       0        1        1        1  -10.6807591
#> 16  303.7415 220.2444       0        1        1        1   -4.2826418
#> 17  314.2088 222.0920       0        1        1        1   -8.4617246
#> 18  324.6761 223.9396       0        1        1        1   -6.2124074
#> 19  335.1434 225.7872       0        1        1        1   -1.4914901
#> 20  345.6107 227.6348       0        1        1        1    9.6794271
#> 21  251.4051 212.4449       0        1        1        1  -13.3909591
#> 22  261.8724 217.4633       0        1        1        1  -23.1310651
#> 23  272.3397 222.4817       0        1        1        1   11.8383288
#> 24  282.8070 227.5001       0        1        1        1    5.3415228
#> 25  293.2742 232.5185       0        1        1        1   -3.2110832
#> 26  303.7415 237.5369       0        1        1        1  -17.0789893
#> 27  314.2088 242.5553       0        1        1        1   -7.1344953
#> 28  324.6761 247.5737       0        1        1        1    8.1773986
#> 29  335.1434 252.5921       0        1        1        1    8.4203926
#> 30  345.6107 257.6105       0        1        1        1  -10.0952135
#> 31  251.4051 275.0956       0        1        1        1   46.4469967
#> 32  261.8724 280.7486       0        1        1        1   19.6516420
#> 33  272.3397 286.4015       0        1        1        1   -2.5450126
#> 34  282.8070 292.0545       0        1        1        1   -6.9214673
#> 35  293.2742 297.7074       0        1        1        1  -11.9101219
#> 36  303.7415 303.3604       0        1        1        1   -5.7748766
#> 37  314.2088 309.0133       0        1        1        1  -28.7737313
#> 38  324.6761 314.6663       0        1        1        1    3.5950141
#> 39  335.1434 320.3192       0        1        1        1  -14.9697406
#> 40  345.6107 325.9722       0        1        1        1   28.0765048
#> 41  251.4051 273.6653       0        1        1        1   13.9425924
#> 42  261.8724 281.0627       0        1        1        1    3.9373011
#> 43  272.3397 288.4601       0        1        1        1   13.3605097
#> 44  282.8070 295.8575       0        1        1        1   24.2578183
#> 45  293.2742 303.2549       0        1        1        1   13.0224270
#> 46  303.7415 310.6523       0        1        1        1  -17.3335644
#> 47  314.2088 318.0497       0        1        1        1  -27.9746558
#> 48  324.6761 325.4470       0        1        1        1    9.3706529
#> 49  335.1434 332.8444       0        1        1        1  -39.0975385
#> 50  345.6107 340.2418       0        1        1        1   31.3392701
#> 51  251.4051 260.4446       0        1        1        1  -25.5840308
#> 52  261.8724 270.6397       0        1        1        1  -27.8279461
#> 53  272.3397 280.8349       0        1        1        1   -7.8735614
#> 54  282.8070 291.0300       0        1        1        1   18.7388233
#> 55  293.2742 301.2251       0        1        1        1   16.2378080
#> 56  303.7415 311.4202       0        1        1        1   -1.4226073
#> 57  314.2088 321.6153       0        1        1        1  132.5465774
#> 58  324.6761 331.8104       0        1        1        1   15.0206621
#> 59  335.1434 342.0056       0        1        1        1  -11.7052532
#> 60  345.6107 352.2007       0        1        1        1  -98.3362685
#> 61  251.4051 268.2455       0        1        1        1   15.5968640
#> 62  261.8724 278.4892       0        1        1        1   11.0658025
#> 63  272.3397 288.7329       0        1        1        1  -11.9635590
#> 64  282.8070 298.9765       0        1        1        1    0.8331794
#> 65  293.2742 309.2202       0        1        1        1  -12.0491821
#> 66  303.7415 319.4638       0        1        1        1   18.7026564
#> 67  314.2088 329.7075       0        1        1        1    2.3189949
#> 68  324.6761 339.9512       0        1        1        1    8.8887334
#> 69  335.1434 350.1948       0        1        1        1  -16.8348282
#> 70  345.6107 360.4385       0        1        1        1    1.6043103
#> 71  251.4051 244.1725       0        1        1        1   21.3005743
#> 72  261.8724 255.7144       0        1        1        1   20.4868123
#> 73  272.3397 267.2562       0        1        1        1  -23.8915497
#> 74  282.8070 278.7981       0        1        1        1  -24.1258118
#> 75  293.2742 290.3400       0        1        1        1  -11.3155738
#> 76  303.7415 301.8818       0        1        1        1  -17.6906358
#> 77  314.2088 313.4237       0        1        1        1   -7.8988979
#> 78  324.6761 324.9656       0        1        1        1    6.5573401
#> 79  335.1434 336.5074       0        1        1        1   -0.7605219
#> 80  345.6107 348.0493       0        1        1        1   29.2497160
#> 81  251.4051 251.0714       0        1        1        1   -9.4631090
#> 82  261.8724 250.7865       0        1        1        1   23.1606641
#> 83  272.3397 250.5017       0        1        1        1    3.9890373
#> 84  282.8070 250.2168       0        1        1        1   20.5853104
#> 85  293.2742 249.9319       0        1        1        1    1.5199836
#> 86  303.7415 249.6470       0        1        1        1    4.9891567
#> 87  314.2088 249.3622       0        1        1        1   -3.9098701
#> 88  324.6761 249.0773       0        1        1        1  -13.7662970
#> 89  335.1434 248.7924       0        1        1        1  -13.0383238
#> 90  345.6107 248.5076       0        1        1        1  -11.2609507
#> 91  251.4051 286.2955       0        1        1        1   26.0711444
#> 92  261.8724 305.3910       0        1        1        1    8.4147745
#> 93  272.3397 324.4866       0        1        1        1  -32.8753955
#> 94  282.8070 343.5822       0        1        1        1    2.5400346
#> 95  293.2742 362.6777       0        1        1        1    3.0546647
#> 96  303.7415 381.7733       0        1        1        1   10.0651948
#> 97  314.2088 400.8689       0        1        1        1    3.3912248
#> 98  324.6761 419.9644       0        1        1        1   -3.2721451
#> 99  335.1434 439.0600       0        1        1        1   16.8042850
#> 100 345.6107 458.1556       0        1        1        1    0.7611151
#> 101 251.4051 226.1950       0        1        1        1    9.9082055
#> 102 261.8724 237.8357       0        1        1        1   -7.5189947
#> 103 272.3397 249.4764       0        1        1        1  -10.5507949
#> 104 282.8070 261.1171       0        1        1        1   -6.1950951
#> 105 293.2742 272.7578       0        1        1        1  -22.0474953
#> 106 303.7415 284.3985       0        1        1        1  -14.6240955
#> 107 314.2088 296.0392       0        1        1        1  -14.4743957
#> 108 324.6761 307.6799       0        1        1        1    0.4221041
#> 109 335.1434 319.3206       0        1        1        1   16.9600039
#> 110 345.6107 330.9613       0        1        1        1   20.6838037
#> 111 251.4051 238.3351       0        1        1        1   17.9616519
#> 112 261.8724 255.4166       0        1        1        1  -11.9623391
#> 113 272.3397 272.4981       0        1        1        1  -16.2935301
#> 114 282.8070 289.5796       0        1        1        1  -34.0525210
#> 115 293.2742 306.6611       0        1        1        1  -37.7446120
#> 116 303.7415 323.7426       0        1        1        1    5.9820971
#> 117 314.2088 340.8241       0        1        1        1   38.6204061
#> 118 324.6761 357.9056       0        1        1        1    5.0128151
#> 119 335.1434 374.9871       0        1        1        1   19.5001242
#> 120 345.6107 392.0686       0        1        1        1   -3.0158668
#> 121 251.4051 255.9829       0        1        1        1   -5.4564400
#> 122 261.8724 263.4350       0        1        1        1   36.6226312
#> 123 272.3397 270.8870       0        1        1        1   -0.9930976
#> 124 282.8070 278.3390       0        1        1        1    2.2500737
#> 125 293.2742 285.7911       0        1        1        1  -13.9636551
#> 126 303.7415 293.2431       0        1        1        1   11.3905161
#> 127 314.2088 300.6951       0        1        1        1  -12.9485127
#> 128 324.6761 308.1471       0        1        1        1  -41.5516414
#> 129 335.1434 315.5992       0        1        1        1    5.9426298
#> 130 345.6107 323.0512       0        1        1        1   24.5143010
#> 131 251.4051 272.2687       0        1        1        1  -50.5915973
#> 132 261.8724 286.2720       0        1        1        1   11.9219034
#> 133 272.3397 300.2753       0        1        1        1   26.6032041
#> 134 282.8070 314.2786       0        1        1        1   32.5769049
#> 135 293.2742 328.2819       0        1        1        1   20.4583056
#> 136 303.7415 342.2852       0        1        1        1   10.5435063
#> 137 314.2088 356.2885       0        1        1        1   -1.8618930
#> 138 324.6761 370.2918       0        1        1        1   -9.8591922
#> 139 335.1434 384.2951       0        1        1        1   -8.6544915
#> 140 345.6107 398.2984       0        1        1        1   -9.7566908
#> 141 251.4051 254.6806       0        1        1        1   17.2429421
#> 142 261.8724 266.0201       0        1        1        1    2.4168396
#> 143 272.3397 277.3596       0        1        1        1  -20.1171630
#> 144 282.8070 288.6991       0        1        1        1  -11.0424655
#> 145 293.2742 300.0386       0        1        1        1   14.7836319
#> 146 303.7415 311.3781       0        1        1        1    5.8354293
#> 147 314.2088 322.7176       0        1        1        1  -24.5822732
#> 148 324.6761 334.0571       0        1        1        1   14.0658242
#> 149 335.1434 345.3966       0        1        1        1   -5.1165784
#> 150 345.6107 356.7361       0        1        1        1    9.7770191
#> 151 251.4051 225.7922       0        1        1        1   -0.5282354
#> 152 261.8724 241.0820       0        1        1        1   -6.5584860
#> 153 272.3397 256.3717       0        1        1        1  -17.4709366
#> 154 282.8070 271.6615       0        1        1        1  -31.1884872
#> 155 293.2742 286.9512       0        1        1        1  -19.4139377
#> 156 303.7415 302.2410       0        1        1        1   41.9527117
#> 157 314.2088 317.5307       0        1        1        1  -36.3826389
#> 158 324.6761 332.8205       0        1        1        1   14.7650105
#> 159 335.1434 348.1102       0        1        1        1   17.0527600
#> 160 345.6107 363.4000       0        1        1        1    8.8288094
#> 161 251.4051 252.2121       0        1        1        1   17.6682554
#> 162 261.8724 261.6913       0        1        1        1   10.7515245
#> 163 272.3397 271.1704       0        1        1        1    6.7284937
#> 164 282.8070 280.6495       0        1        1        1    1.1399628
#> 165 293.2742 290.1287       0        1        1        1  -10.9581681
#> 166 303.7415 299.6078       0        1        1        1  -15.0957989
#> 167 314.2088 309.0869       0        1        1        1  -49.8211298
#> 168 324.6761 318.5661       0        1        1        1  -13.9354607
#> 169 335.1434 328.0452       0        1        1        1   22.7355085
#> 170 345.6107 337.5243       0        1        1        1   31.9448776
#> 171 251.4051 263.7196       0        1        1        1    5.6920558
#> 172 261.8724 275.4710       0        1        1        1   -1.9969599
#> 173 272.3397 287.2223       0        1        1        1   10.3745244
#> 174 282.8070 298.9736       0        1        1        1   11.6580087
#> 175 293.2742 310.7249       0        1        1        1  -23.5523070
#> 176 303.7415 322.4762       0        1        1        1    7.1313773
#> 177 314.2088 334.2275       0        1        1        1    0.2542616
#> 178 324.6761 345.9789       0        1        1        1   -2.7589541
#> 179 335.1434 357.7302       0        1        1        1   11.4115302
#> 180 345.6107 369.4815       0        1        1        1   -5.3578855

Created on 2018-12-20 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-11-30 r75724)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       Asia/Calcutta                                     
#>  date     2018-12-20                                        
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version     date       lib
#>  assertthat    0.2.0       2017-04-11 [1]
#>  backports     1.1.3       2018-12-14 [1]
#>  bindr         0.1.1       2018-03-13 [1]
#>  bindrcpp      0.2.2       2018-03-29 [1]
#>  broom         0.5.1.9000  2018-12-19 [1]
#>  broom.mixed * 0.2.3.9000  2018-11-28 [1]
#>  callr         3.1.0       2018-12-10 [1]
#>  cli           1.0.1.9000  2018-10-30 [1]
#>  coda          0.19-2      2018-10-08 [1]
#>  crayon        1.3.4       2017-09-16 [1]
#>  desc          1.2.0       2018-10-30 [1]
#>  devtools      2.0.1       2018-10-26 [1]
#>  digest        0.6.18      2018-10-10 [1]
#>  dplyr         0.7.8       2018-11-10 [1]
#>  evaluate      0.12        2018-10-09 [1]
#>  fansi         0.4.0       2018-11-05 [1]
#>  fs            1.2.6       2018-08-23 [1]
#>  generics      0.0.2       2018-11-29 [1]
#>  glmmTMB       0.2.2.0     2018-07-03 [1]
#>  glue          1.3.0       2018-07-17 [1]
#>  highr         0.7         2018-06-09 [1]
#>  htmltools     0.3.6       2017-04-28 [1]
#>  knitr         1.21        2018-12-10 [1]
#>  lattice       0.20-38     2018-11-04 [2]
#>  lme4        * 1.1-19      2018-11-10 [1]
#>  magrittr      1.5         2014-11-22 [1]
#>  MASS          7.3-51.1    2018-11-01 [2]
#>  Matrix      * 1.2-15      2018-11-01 [1]
#>  memoise       1.1.0       2017-04-21 [1]
#>  minqa         1.2.4       2014-10-09 [1]
#>  nlme          3.1-137     2018-04-07 [2]
#>  nloptr        1.2.1       2018-10-03 [1]
#>  pillar        1.3.1       2018-12-15 [1]
#>  pkgbuild      1.0.2       2018-10-16 [1]
#>  pkgconfig     2.0.2       2018-08-16 [1]
#>  pkgload       1.0.2       2018-10-29 [1]
#>  plyr          1.8.4       2016-06-08 [1]
#>  prettyunits   1.0.2       2015-07-13 [1]
#>  processx      3.2.1       2018-12-05 [1]
#>  ps            1.2.1       2018-11-06 [1]
#>  purrr         0.2.5.9000  2018-11-28 [1]
#>  R6            2.3.0       2018-10-04 [1]
#>  Rcpp          1.0.0       2018-11-07 [1]
#>  remotes       2.0.2       2018-10-30 [1]
#>  reshape2      1.4.3       2017-12-11 [1]
#>  rlang         0.3.0.1     2018-10-25 [1]
#>  rmarkdown     1.11        2018-12-08 [1]
#>  rprojroot     1.3-2       2018-01-03 [1]
#>  sessioninfo   1.1.1       2018-11-05 [1]
#>  stringi       1.2.4       2018-07-20 [1]
#>  stringr       1.3.1       2018-05-10 [1]
#>  testthat      2.0.1       2018-10-13 [1]
#>  tibble        1.4.99.9006 2018-12-19 [1]
#>  tidyr         0.8.2       2018-10-28 [1]
#>  tidyselect    0.2.5       2018-10-11 [1]
#>  TMB           1.7.15      2018-11-09 [1]
#>  usethis       1.4.0.9000  2018-12-12 [1]
#>  utf8          1.1.4       2018-05-24 [1]
#>  withr         2.1.2       2018-03-15 [1]
#>  xfun          0.4         2018-10-23 [1]
#>  yaml          2.2.0       2018-07-25 [1]
#>  source                              
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (tidymodels/broom@1c394a7)   
#>  Github (bbolker/broom.mixed@b3ad950)
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/cli@56538e3)          
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (r-lib/desc@7c12d36)         
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (brodieG/fansi@ab11e9c)      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  Github (tidyverse/purrr@b4ae036)    
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (tidyverse/tibble@181aaab)   
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/usethis@923dd75)      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-devel/library

do we want df included in output where available?

why not:

  • clutters up output
  • not available in some cases
  • wasn't included in original broom tidiers (for whatever reason)

why:

  • might want to see it sometimes
  • it's easy enough to drop with a select(-df)
  • dplyr::bind_rows() makes incommensurate columns in different sets of output fairly harmless

term naming

It would be good to come up with a unified scheme for naming parameters (e.g. the random-effects correlation between A and B with grouping variable C) and finding streamlined ways to translate from, e.g. the MCMCglmm or brms naming convention to the standard

adding confidence intervals for `gls` tidiers

These are available for gls models, but currently broom.mixed::tidy.gls() doesn't output them.

# session setup
set.seed(123)
library(nlme)

# model
fit <-
  nlme::gls(
    model = follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time),
    data = Ovary,
    correlation = corAR1(form = ~ 1 | Mare)
  )

# tidier
broom.mixed::tidy(fit, conf.int = TRUE, conf.level = 0.95)
#> Registered S3 methods overwritten by 'broom.mixed':
#>   method         from 
#>   augment.lme    broom
#>   augment.merMod broom
#>   glance.lme     broom
#>   glance.merMod  broom
#>   glance.stanreg broom
#>   tidy.brmsfit   broom
#>   tidy.gamlss    broom
#>   tidy.lme       broom
#>   tidy.merMod    broom
#>   tidy.rjags     broom
#>   tidy.stanfit   broom
#>   tidy.stanreg   broom
#> # A tibble: 3 x 5
#>   term               estimate std.error statistic  p.value
#>   <chr>                 <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)          12.2       0.665     18.4  2.62e-51
#> 2 sin(2 * pi * Time)   -2.77      0.645     -4.30 2.29e- 5
#> 3 cos(2 * pi * Time)   -0.900     0.698     -1.29 1.98e- 1

# confidence intervals
stats::confint(fit)
#>                        2.5 %     97.5 %
#> (Intercept)        10.913721 13.5190758
#> sin(2 * pi * Time) -4.038983 -1.5104418
#> cos(2 * pi * Time) -2.266755  0.4675452

Created on 2018-11-23 by the reprex package (v0.2.1)

consistency in term names for zi components; keep or strip zi_ tags?

dotwhisker::dwplot might have surprising results on glmmTMB models with zero-inflation/disp components, where the term variable has its tags stripped (in contrast to brms, which currently includes a zi_ tag for zero-inflation parameters ... Adding such a tag is slightly counter to the broom.mixed principles (include all info as separate column, it's easier to recombine than to split post hoc), but might be worth it for minimal surprise.

extra columns in augment?

from @wpetry:

It may be worthwhile to add language to the augment.glmmTMB documentation that explains additional columns that may appear. For example, a model fit with glmmTMB(..., weights = someColumn, ...) will add a column called X.weights. Cleaning up these naming conventions would be better as an issue for broom. broom.mixed could simply offer blanket text about other common model components being included as columns.

`conf.int` not working for glmmTMB objects

library(glmmTMB)
library(broom.mixed)

m1 <- glmmTMB(count~ mined + (1|site), 
              zi=~mined, 
              family=poisson, data=Salamanders)

broom.mixed::tidy(m1, conf.int = TRUE, conf.level = .95)
#> Error in ci[parm, , drop = FALSE]: subscript out of bounds

broom.mixed::tidy(m1, conf.int = TRUE, conf.level = .5)
#> Error in ci[parm, , drop = FALSE]: subscript out of bounds

Created on 2018-10-04 by the reprex package (v0.2.1)

tidy() confuses response and group values for brms-mv-models

For the random-effect intercepts, the values in the columns response and group of tidy() are inverted, and the values in the term-column contain NA in its description.

I think these models are very special, and hence this issue probably can't be fixed quickly, so I would not add this to the wish-list for the next update...

library(sjstats)
library(brms)
library(broom.mixed)

data(efc)

f3 <- bf(neg_c_7 ~ e42dep + c12hour + c172code + (1 |ID| e15relat))
f4 <- bf(c12hour ~ c172code + (1 |ID| e15relat))
b14 <- brm(f3 + f4 + set_rescor(FALSE), data = efc, iter = 500, chains = 1)

b14
#>  Family: MV(gaussian, gaussian) 
#>   Links: mu = identity; sigma = identity
#>          mu = identity; sigma = identity 
#> Formula: neg_c_7 ~ e42dep + c12hour + c172code + (1 | ID | e15relat) 
#>          c12hour ~ c172code + (1 | ID | e15relat) 
#>    Data: efc (Number of observations: 834) 
#> Samples: 1 chains, each with iter = 500; warmup = 250; thin = 1;
#>          total post-warmup samples = 250
#> 
#> Group-Level Effects: 
#> ~e15relat (Number of levels: 8) 
#>                                        Estimate Est.Error l-95% CI
#> sd(negc7_Intercept)                        0.59      0.33     0.13
#> sd(c12hour_Intercept)                     23.67      6.84    14.91
#> cor(negc7_Intercept,c12hour_Intercept)     0.52      0.36    -0.36
#>                                        u-95% CI Eff.Sample Rhat
#> sd(negc7_Intercept)                        1.32         96 1.02
#> sd(c12hour_Intercept)                     40.34        154 1.05
#> cor(negc7_Intercept,c12hour_Intercept)     0.97         39 1.04
#> 
#> Population-Level Effects: 
#>                   Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
#> negc7_Intercept       6.78      0.58     5.68     7.86        250 1.00
#> c12hour_Intercept    41.44      9.73    22.92    60.36        173 1.01
#> negc7_e42dep          1.34      0.15     1.05     1.60        250 1.00
#> negc7_c12hour         0.01      0.00     0.00     0.01        250 1.00
#> negc7_c172code        0.33      0.20    -0.06     0.70        250 1.00
#> c12hour_c172code     -3.67      2.63    -8.77     0.97        150 1.00
#> 
#> Family Specific Parameters: 
#>               Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
#> sigma_negc7       3.58      0.09     3.43     3.76        250 1.00
#> sigma_c12hour    46.33      1.15    43.96    48.79        250 1.00
#> 
#> Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample 
#> is a crude measure of effective sample size, and Rhat is the potential 
#> scale reduction factor on split chains (at convergence, Rhat = 1).

tidy_stan(b14, type = "all")
#> 
#> # Summary Statistics of Stan-Model
#> 
#> ## Fixed effects for response: negc7
#> 
#>            estimate std.error      HDI(89%) ratio rhat mcse
#>  Intercept     6.75      0.57 [ 5.91  7.69]     1    1 0.04
#>  e42dep        1.34      0.16 [ 1.12  1.57]     1    1 0.01
#>  c12hour       0.01      0.00 [ 0.00  0.01]     1    1 0.00
#>  c172code      0.32      0.20 [ 0.05  0.69]     1    1 0.01
#> 
#> ## Random effect (Intercept: e15relat) for response negc7
#> 
#>             estimate std.error      HDI(89%) ratio rhat mcse
#>  e15relat.1     0.63      0.45 [-0.01  1.46]  0.23 1.03 0.06
#>  e15relat.2     0.33      0.35 [-0.18  0.88]  0.33 1.00 0.04
#>  e15relat.3    -0.08      0.31 [-0.84  0.54]  0.68 1.00 0.03
#>  e15relat.4    -0.02      0.29 [-0.57  0.61]  0.37 1.01 0.04
#>  e15relat.5    -0.18      0.37 [-1.04  0.46]  0.48 1.00 0.04
#>  e15relat.6    -0.55      0.51 [-1.47  0.16]  0.49 1.00 0.05
#>  e15relat.7     0.15      0.49 [-0.65  1.10]  1.00 1.02 0.04
#>  e15relat.8    -0.21      0.31 [-0.74  0.28]  0.31 1.00 0.04
#> 
#> ## Fixed effects for response: c12hour
#> 
#>            estimate std.error      HDI(89%) ratio rhat mcse
#>  Intercept    40.99      9.93 [26.15 57.00]  0.69 1.01 0.74
#>  c172code     -3.59      2.74 [-7.60  0.25]  0.60 1.00 0.21
#> 
#> ## Random effect (Intercept: e15relat) for response c12hour
#> 
#>             estimate std.error       HDI(89%) ratio rhat mcse
#>  e15relat.1    47.18      9.36 [ 35.02 62.55]  0.50 1.02 0.78
#>  e15relat.2     2.58      8.06 [-11.09 14.77]  0.52 1.03 0.72
#>  e15relat.3     0.12     10.27 [-15.99 15.00]  0.50 1.02 0.87
#>  e15relat.4    -0.50      9.26 [-13.31 15.10]  0.65 1.02 0.70
#>  e15relat.5   -15.90     12.68 [-36.28  1.29]  1.00 1.00 0.77
#>  e15relat.6   -19.46     12.56 [-37.71 -0.25]  1.00 1.00 0.77
#>  e15relat.7    20.65     16.87 [ -4.98 49.87]  1.00 1.01 1.07
#>  e15relat.8   -13.11      9.56 [-27.17  2.29]  0.67 1.02 0.69

broom.mixed::tidy(b14, conf.int = FALSE)
#> # A tibble: 11 x 7
#>    response effect  component group      term           estimate std.error
#>    <chr>    <chr>   <chr>     <chr>      <chr>             <dbl>     <dbl>
#>  1 negc7    fixed   cond      <NA>       (Intercept)     6.78e+0   0.578  
#>  2 c12hour  fixed   cond      <NA>       (Intercept)     4.14e+1   9.73   
#>  3 negc7    fixed   cond      <NA>       e42dep          1.34e+0   0.146  
#>  4 negc7    fixed   cond      <NA>       c12hour         6.26e-3   0.00278
#>  5 negc7    fixed   cond      <NA>       c172code        3.29e-1   0.204  
#>  6 c12hour  fixed   cond      <NA>       c172code       -3.67e+0   2.63   
#>  7 e15relat ran_pa~ cond      negc7_Int~ sd__NA.negc7_~  5.90e-1   0.329  
#>  8 e15relat ran_pa~ cond      c12hour_I~ sd__NA.c12hou~  2.37e+1   6.84   
#>  9 e15relat ran_pa~ cond      negc7_Int~ cor__c12hour_~  5.20e-1   0.356  
#> 10 negc7    ran_pa~ cond      Residual   sd__Observati~  3.58e+0   0.0870 
#> 11 c12hour  ran_pa~ cond      Residual   sd__Observati~  4.63e+1   1.15

Created on 2018-10-14 by the reprex package (v0.2.1)

mcmc tidier doesn't work with `ess = TRUE`

# loading the data
set.seed(123)
library(coda)
data(line)

# select first chain
x1 <- line[[1]]

# with default arguments (works)
broom.mixed::tidy(x = x1,
                  conf.int = TRUE)

#> # A tibble: 3 x 5
#>   term  estimate std.error conf.low conf.high
#>   <chr>    <dbl>     <dbl>    <dbl>     <dbl>
#> 1 alpha    2.97      0.531    2.09       3.84
#> 2 beta     0.792     0.341    0.141      1.38
#> 3 sigma    0.778     0.889    0.425      2.36

# additional arguments (doesn't work)
broom.mixed::tidy(
  x = x1,
  conf.int = TRUE,
  robust = TRUE,
  rhat = TRUE,
  index = TRUE,
  ess = TRUE
)

#> Warning in tidy.mcmc(x = x1, conf.int = TRUE, robust = TRUE, rhat = TRUE, :
#> ignoring 'rhat' and 'ess' (only available for stanfit objects)
#> Error in round(summ[, "n_eff"]): non-numeric argument to mathematical function

# works again if `ess` argument is commented out
broom.mixed::tidy(
  x = x1,
  conf.int = TRUE,
  robust = TRUE,
  rhat = TRUE,
  index = TRUE,
  #ess = TRUE
)

#> Warning in tidy.mcmc(x = x1, conf.int = TRUE, robust = TRUE, rhat = TRUE, :
#> ignoring 'rhat' and 'ess' (only available for stanfit objects)
#> # A tibble: 3 x 6
#>   term  index estimate std.error conf.low conf.high
#>   <chr> <int>    <dbl>     <dbl>    <dbl>     <dbl>
#> 1 alpha    NA    2.98      0.378    2.09       3.84
#> 2 beta     NA    0.787     0.264    0.141      1.38
#> 3 sigma    NA    0.954     0.289    0.425      2.36

Here is traceback for the instance when the function fails-

traceback()
2: tidy.mcmc(x = x1, conf.int = TRUE, robust = TRUE, rhat = TRUE, 
       index = TRUE, ess = TRUE)
1: broom.mixed::tidy(x = x1, conf.int = TRUE, robust = TRUE, rhat = TRUE, 
       index = TRUE, ess = TRUE)
Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-11-30 r75724)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       America/New_York                                  
#>  date     2019-02-05                                        
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib
#>  assertthat    0.2.0      2017-04-11 [1]
#>  backports     1.1.3      2018-12-14 [1]
#>  broom         0.5.1.9000 2019-01-20 [1]
#>  broom.mixed   0.2.3.9000 2019-01-23 [1]
#>  callr         3.1.1      2018-12-21 [1]
#>  cli           1.0.1.9000 2019-01-20 [1]
#>  coda        * 0.19-2     2018-10-08 [1]
#>  colorspace    1.4-0      2019-01-13 [1]
#>  crayon        1.3.4      2017-09-16 [1]
#>  desc          1.2.0      2019-01-21 [1]
#>  devtools      2.0.1.9000 2019-01-29 [1]
#>  digest        0.6.18     2018-10-10 [1]
#>  dplyr         0.8.0      2019-01-31 [1]
#>  evaluate      0.12       2018-10-09 [1]
#>  fansi         0.4.0      2018-11-05 [1]
#>  fs            1.2.6      2018-08-23 [1]
#>  generics      0.0.2      2019-01-20 [1]
#>  ggplot2       3.1.0.9000 2019-01-31 [1]
#>  glue          1.3.0      2018-07-17 [1]
#>  gridExtra     2.3        2017-09-09 [1]
#>  gtable        0.2.0      2016-02-26 [1]
#>  highr         0.7        2018-06-09 [1]
#>  htmltools     0.3.6      2017-04-28 [1]
#>  inline        0.3.15     2018-05-18 [1]
#>  knitr         1.21       2018-12-10 [1]
#>  lattice       0.20-38    2018-11-04 [2]
#>  lazyeval      0.2.1      2017-10-29 [1]
#>  loo           2.0.0      2018-04-11 [1]
#>  magrittr      1.5        2014-11-22 [1]
#>  Matrix        1.2-15     2018-11-01 [1]
#>  matrixStats   0.54.0     2018-07-23 [1]
#>  memoise       1.1.0      2017-04-21 [1]
#>  munsell       0.5.0      2018-06-12 [1]
#>  nlme          3.1-137    2018-04-07 [2]
#>  pillar        1.3.1      2018-12-15 [1]
#>  pkgbuild      1.0.2      2018-10-16 [1]
#>  pkgconfig     2.0.2      2018-08-16 [1]
#>  pkgload       1.0.2      2018-10-29 [1]
#>  plyr          1.8.4      2016-06-08 [1]
#>  prettyunits   1.0.2      2015-07-13 [1]
#>  processx      3.2.1      2018-12-05 [1]
#>  ps            1.3.0      2018-12-21 [1]
#>  purrr         0.3.0      2019-01-25 [1]
#>  R6            2.3.0      2018-10-04 [1]
#>  Rcpp          1.0.0      2018-11-07 [1]
#>  remotes       2.0.2      2018-10-30 [1]
#>  reshape2      1.4.3      2017-12-11 [1]
#>  rlang         0.3.1      2019-01-08 [1]
#>  rmarkdown     1.11       2018-12-08 [1]
#>  rprojroot     1.3-2      2018-01-03 [1]
#>  rstan         2.18.2     2018-11-07 [1]
#>  scales        1.0.0      2018-08-09 [1]
#>  sessioninfo   1.1.1      2018-11-05 [1]
#>  StanHeaders   2.18.1     2019-01-28 [1]
#>  stringi       1.2.4      2018-07-20 [1]
#>  stringr       1.3.1      2018-05-10 [1]
#>  testthat      2.0.1      2018-10-13 [1]
#>  tibble        2.0.1      2019-01-12 [1]
#>  tidyr         0.8.2      2018-10-28 [1]
#>  tidyselect    0.2.5      2018-10-11 [1]
#>  TMB           1.7.15     2018-11-09 [1]
#>  usethis       1.4.0.9000 2019-01-29 [1]
#>  utf8          1.1.4      2018-05-24 [1]
#>  withr         2.1.2      2018-03-15 [1]
#>  xfun          0.4        2018-10-23 [1]
#>  yaml          2.2.0      2018-07-25 [1]
#>  source                              
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  Github (tidymodels/broom@66411c4)   
#>  Github (bbolker/broom.mixed@fbe9597)
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/cli@94e2fc5)          
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  Github (r-lib/desc@42b9578)         
#>  Github (r-lib/devtools@e4e57aa)     
#>  CRAN (R 3.5.1)                      
#>  Github (tidyverse/dplyr@67b9f4f)    
#>  CRAN (R 3.5.1)                      
#>  Github (brodieG/fansi@ab11e9c)      
#>  CRAN (R 3.5.1)                      
#>  Github (r-lib/generics@d59e6b4)     
#>  Github (tidyverse/ggplot2@54e773b)  
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  Github (tidyverse/purrr@240f7b2)    
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.2)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.2)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/usethis@5a0680b)      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-devel/library

`component` argument fails for random effects

library(glmmTMB)
library(broom.mixed)

m1 <- glmmTMB(count~ mined + (1|site), 
              zi=~mined, 
              family=poisson, data=Salamanders)

broom.mixed::tidy(m1, effects = "ran_pars", component = "cond")
#> # A tibble: 1 x 5
#>   effect   component group term            estimate
#>   <chr>    <chr>     <chr> <chr>              <dbl>
#> 1 ran_pars cond      site  sd__(Intercept)    0.280

broom.mixed::tidy(m1, effects = "ran_pars", component = "zi")
#> Error: Columns `var1`, `var2` not found

Created on 2018-10-04 by the reprex package (v0.2.1)

lme tidying fails with pdDiag model

library(broom.mixed)
load(system.file("extdata","nlme_example.rda",package="broom.mixed"))
tidy(lmm2)
Error: Columns `effect`, `group` must be length 1 or 4, not 3, 3

insert_NAs potentially messed up by additional NAs in original data

(this is really a broom problem, but we can fix it here and potentially backport it)

This logic is doing something very similar to stats::napredict - we might be able to replace it.
The problem arises when the original data have additional columns (not used in the model) that contain NAs; then which(stats::complete.cases(original)) is shorter than the prediction/augmentation data frame ...

insert_NAs <- function(x, original) {
    indices <- rep(NA, nrow(original))
    indices[which(stats::complete.cases(original))] = seq_len(nrow(x))
    x[indices, ]
}

warning with `R 3.6`

With the development version of R I am getting the following warning once per session. Is this expected? Wasn't getting any such warning with 3.5, so just wanted to raise this issue before the next release.

Registered S3 methods overwritten by 'broom.mixed':
  method         from 
  augment.lme    broom
  augment.merMod broom
  glance.lme     broom
  glance.merMod  broom
  glance.stanreg broom
  tidy.brmsfit   broom
  tidy.gamlss    broom
  tidy.lme       broom
  tidy.merMod    broom
  tidy.rjags     broom
  tidy.stanfit   broom
  tidy.stanreg   broom

storing fitted objects for examples and tests

It will be useful to store fitted models from a wide variety of packages so that they can be retrieved for examples and testing. This has two major benefits: (1) examples and tests can be run without packages installed; (2) saves lots of time in examples/testing (because fits don't actually have to be computed).

The major downside to this is that we therefore won't know when there are changes in the upstream packages that cause problems.

The way to resolve this is probably to set up an automated system for updating all of the packaged fits, and to do this frequently ...

`conf.level` not working for merMod objects

Argument conf.level does not affect the confidence intervals in the output...

library(lme4)
#> Loading required package: Matrix
library(broom.mixed)

m <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), cbpp, binomial, nAGQ = 0)

broom.mixed::tidy(m, conf.int = TRUE, conf.level = .95)
#> # A tibble: 5 x 9
#>   effect group term  estimate std.error statistic  p.value conf.low
#>   <chr>  <chr> <chr>    <dbl>     <dbl>     <dbl>    <dbl>    <dbl>
#> 1 fixed  <NA>  (Int~   -1.36      0.228     -5.98  2.26e-9    -1.81
#> 2 fixed  <NA>  peri~   -0.976     0.303     -3.22  1.29e-3    -1.57
#> 3 fixed  <NA>  peri~   -1.11      0.324     -3.43  5.94e-4    -1.75
#> 4 fixed  <NA>  peri~   -1.56      0.424     -3.67  2.38e-4    -2.39
#> 5 ran_p~ herd  sd__~    0.642    NA         NA    NA          NA   
#> # ... with 1 more variable: conf.high <dbl>

broom.mixed::tidy(m, conf.int = TRUE, conf.level = .5)
#> # A tibble: 5 x 9
#>   effect group term  estimate std.error statistic  p.value conf.low
#>   <chr>  <chr> <chr>    <dbl>     <dbl>     <dbl>    <dbl>    <dbl>
#> 1 fixed  <NA>  (Int~   -1.36      0.228     -5.98  2.26e-9    -1.81
#> 2 fixed  <NA>  peri~   -0.976     0.303     -3.22  1.29e-3    -1.57
#> 3 fixed  <NA>  peri~   -1.11      0.324     -3.43  5.94e-4    -1.75
#> 4 fixed  <NA>  peri~   -1.56      0.424     -3.67  2.38e-4    -2.39
#> 5 ran_p~ herd  sd__~    0.642    NA         NA    NA          NA   
#> # ... with 1 more variable: conf.high <dbl>

Created on 2018-10-04 by the reprex package (v0.2.1)

Generate test data

For testing Stan/brms-based functions on CRAN, prepared data are required to avoid long compile times. Currently (including my PR), there is a run_examples.R file in inst/extdata to generate rds-files.

I suggest to follow @paul-buerkner 's brms package to make sure these files are updated for releases:

  • rename run_examples.R to generate_test_data.R and put these into ./tests
  • It will be run on normal tests - maybe provide some environment to avoid running it in your daily work
  • Add generate_test_data.R to .Rbuildignore to avoid running it on CRAN

If ok, I will submit a PR

Additional column "response" for multivariate response models in Stan?

It would be nice if tidy() would return an additional column, e.g. response or similar, for multivariate response models fitted with brms or rstanarm.

I've done this in one of my packages with an own tidy-method, so I can plot the estimates for each regression in a separate panel (facet) by specifying this response-variable as facet_wrap()...

library(brms)
library(sjPlot)
#> Learn more about sjPlot with 'browseVignettes("sjPlot")'.
library(broom.mixed)

data(efc)

f1 <- bf(neg_c_7 ~ e42dep + c12hour + c172code)
f2 <- bf(c12hour ~ c172code)
m <- brm(f1 + f2 + set_rescor(FALSE), data = efc, chains = 1, iter = 500)

sjPlot:::tidy_stan_model(m, ci.lvl = .95, tf = NULL, type = "fe", bpe = "mean", show.zeroinf = T, facets = F)
#>   response.level      term     estimate   std.error      conf.low
#> 1          negc7 Intercept  6.925453740 0.661863672   5.818459143
#> 2        c12hour Intercept 56.579035109 6.022554211  46.413222361
#> 3          negc7    e42dep  1.361157783 0.151324820   1.091126414
#> 4          negc7   c12hour  0.008307582 0.002479849   0.003246346
#> 5          negc7  c172code  0.307748022 0.242874356  -0.103908521
#> 6        c12hour  c172code -7.299358533 2.905972218 -12.834432372
#> 7  (... remaining columns truncated in output)

broom.mixed::tidy(m, effects = "fixed")
#> # A tibble: 6 x 6
#>   effect term               estimate std.error  conf.low conf.high
#>   <chr>  <chr>                 <dbl>     <dbl>     <dbl>     <dbl>
#> 1 fixed  negc7_Intercept     6.93      0.623     5.82       8.06  
#> 2 fixed  c12hour_Intercept  56.6       5.98     46.5       68.0   
#> 3 fixed  negc7_e42dep        1.36      0.150     1.10       1.66  
#> 4 fixed  negc7_c12hour       0.00831   0.00268   0.00325    0.0136
#> 5 fixed  negc7_c172code      0.308     0.227    -0.0945     0.696 
#> 6 fixed  c12hour_c172code   -7.30      2.98    -12.9       -2.07

Created on 2018-10-05 by the reprex package (v0.2.1)

feature request: supporting `glmmFit` class objects

# setup
set.seed(123)
library(glmmsr)

# model
mod <-
  glmmsr::glmm(
    formula = response ~ covariate + (1 | cluster),
    data = two_level,
    family = binomial,
    method = "AGQ",
    control = list(nAGQ = 16)
  )
#> Fitting the model. done.

# class of object
class(mod)
#> [1] "glmmFit"

# summary
summary(mod)
#> Generalized linear mixed model fit by maximum likelihood [glmmFit] 
#> Likelihood approximation: Adaptive Gaussian Quadrature with 16 points (lme4) 
#>  
#> Family: binomial ( logit ) 
#> Formula: response ~ covariate + (1 | cluster)
#> 
#> Random effects:
#>  Groups  Name        Estimate Std.Error
#>  cluster (Intercept) 1.041    0.5926   
#> Number of obs: 100, groups: cluster, 50; 
#> 
#> Fixed effects: 
#>             Estimate Std. Error z value Pr(>|z|)
#> (Intercept)   0.7168     0.3980   1.801  0.07172
#> covariate    -1.2734     0.5735   2.220  0.02639

# confidence intervals
confint.default(mod)
#>                     2.5 %     97.5 %
#> RE(Intercept) -0.12067442  2.2022207
#> (Intercept)   -0.06331442  1.4968362
#> covariate     -2.39736544 -0.1494037

Created on 2019-02-05 by the reprex package (v0.2.1)

release-critical/wishlist for 0.2.3 ?

CRAN wants a new version by October 22 (the previous version didn't deal properly with making use of Suggested packages conditional, and some of rstanarm/etc. no longer install on r-release ...).

I believe the release-critical issues are dealt with, but anyone who is following the issues could suggest release-critical and/or low-hanging wishlist items. I've started a vignette and would like to improve it a bit more before submitting, if possible ...

feature request: partially linear mixed effects model (`plmm`) models

# setup
set.seed(123)
library(plmm)
#> Loading required package: sm
#> Package 'sm', version 2.2-5.6: type help(sm) for summary information
#> Loading required package: Formula
#> Loading required package: nlme
data(plmm.data)

# model
mod <-
  plmm::plmm(formula = y0 ~ x1 + x2 + x3 |
               t1,
             random = cluster,
             data = plmm.data)

# class
class(mod)
#> [1] "plmm"

# summary
summary(mod)
#> Partially Linear Mixed Effects Model 
#> Call:
#> plmm::plmm(formula = y0 ~ x1 + x2 + x3 | t1, random = cluster,      data = plmm.data) 
#> Convergence after 3 iterations 
#> 
#> Variance components (FC) :
#>       cluster idiosyncratic 
#>      2.141472      1.090061 
#> 
#> Fixed coefficients:
#>      Estimate
#> x1  0.9479039
#> x2  0.5057765
#> x3 -1.0128097
#> 
#> Nonparametric component: t1 
#> Method: Local Linear 
#> Bandwidth selection: h.select 
#> Bandwidth: 0.5225235

Created on 2018-12-26 by the reprex package (v0.2.1)

refactor lme4/nlme/glmmTMB/(glmmADMB?) tidiers

I've gradually been refactoring the lme4 tidiers, moving away from the broom::fix*() functions - instead, make sure columns are renamed appropriately on the fly, and use tibble::rownames_to_column() as appropriate. Need to make sure that code is re-used appropriately and that behaviour is a similar as possible across these cases.

travis issues

First attempt at a travis build timed out while trying to install all the packages. Possible solutions here.

tidier for `rjags` models not working

# setup
set.seed(123)
library(R2jags)
#> Loading required package: rjags
#> Loading required package: coda
#> Linked to JAGS 4.3.0
#> Loaded modules: basemod,bugs
#> 
#> Attaching package: 'R2jags'
#> The following object is masked from 'package:coda':
#> 
#>     traceplot

# An example model file is given in:
model.file <- system.file(package = "R2jags", "model", "schools.txt")

# Let's take a look:
file.show(model.file)

# data
J <- 8.0
y <- c(28.4, 7.9, -2.8, 6.8, -0.6, 0.6, 18.0, 12.2)
sd <- c(14.9, 10.2, 16.3, 11.0, 9.4, 11.4, 10.4, 17.6)

# setting up model
jags.data <- list("y", "sd", "J")
jags.params <- c("mu", "sigma", "theta")
jags.inits <- function() {
  list("mu" = rnorm(1), "sigma" = runif(1), "theta" = rnorm(J))
}

# model fitting
jagsfit <- R2jags::jags(
  data = list("y", "sd", "J"),
  inits = jags.inits,
  jags.params,
  n.iter = 10,
  model.file = model.file
)
#> module glm loaded
#> Compiling model graph
#>    Resolving undeclared variables
#>    Allocating nodes
#> Graph information:
#>    Observed stochastic nodes: 8
#>    Unobserved stochastic nodes: 10
#>    Total graph size: 41
#> 
#> Initializing model

# checking class
class(jagsfit)
#> [1] "rjags"

# printing output
print(jagsfit)
#> Inference for Bugs model at "C:/Users/inp099/Documents/R/win-library/3.6/R2jags/model/schools.txt", fit using jags,
#>  3 chains, each with 10 iterations (first 5 discarded)
#>  n.sims = 15 iterations saved
#>          mu.vect sd.vect   2.5%    25%    50%    75%  97.5%   Rhat n.eff
#> mu        -0.321   1.373 -1.696 -1.668 -0.771  1.226  1.851  9.327     3
#> sigma      0.710   0.535  0.036  0.088  0.764  1.120  1.437  6.747     3
#> theta[1]  -0.004   1.620 -1.682 -1.627 -0.211  0.685  2.922  3.214     4
#> theta[2]  -0.073   1.654 -2.087 -1.653 -0.100  1.191  2.703  3.419     3
#> theta[3]  -0.613   1.168 -1.764 -1.695 -0.727 -0.133  1.857  2.210     4
#> theta[4]  -0.719   1.237 -1.776 -1.653 -1.622  0.116  1.713  2.520     4
#> theta[5]  -0.439   1.377 -1.715 -1.597 -0.866  0.540  2.181  2.313     4
#> theta[6]  -0.094   1.701 -1.714 -1.586 -0.472  1.173  2.841  4.855     3
#> theta[7]  -0.312   1.571 -1.722 -1.629 -1.041  1.043  2.415  5.438     3
#> theta[8]  -0.556   1.335 -2.465 -1.621 -0.746  0.420  1.584  3.034     4
#> deviance  63.376   1.274 61.435 61.983 63.673 64.674 64.713 10.813     3
#> 
#> For each parameter, n.eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor (at convergence, Rhat=1).
#> 
#> DIC info (using the rule, pD = var(deviance)/2)
#> pD = 0.0 and DIC = 63.4
#> DIC is an estimate of expected predictive error (lower deviance is better).

# getting tidy output
broom.mixed::tidy(
  x = jagsfit,
  conf.int = TRUE,
  conf.method = "quantile"
)
#> Error in character(ncol(y)): invalid 'length' argument

Here is the traceback

> traceback()
6: character(ncol(y))
5: as.matrix.mcmc(x)
4: as.matrix(x)
3: tidyMCMC(as.mcmc(x$BUGS), estimate.method, conf.int, conf.level, 
       conf.method, drop.pars = "deviance")
2: tidy.rjags(x = jagsfit, conf.int = TRUE, conf.method = "quantile")
1: broom.mixed::tidy(x = jagsfit, conf.int = TRUE, conf.method = "quantile")
Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-11-30 r75724)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       America/New_York                                  
#>  date     2019-02-05                                        
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib
#>  abind         1.4-5      2016-07-21 [1]
#>  assertthat    0.2.0      2017-04-11 [1]
#>  backports     1.1.3      2018-12-14 [1]
#>  boot          1.3-20     2017-08-06 [2]
#>  broom         0.5.1.9000 2019-01-20 [1]
#>  broom.mixed   0.2.3.9000 2019-01-23 [1]
#>  callr         3.1.1      2018-12-21 [1]
#>  cli           1.0.1.9000 2019-01-20 [1]
#>  coda        * 0.19-2     2018-10-08 [1]
#>  crayon        1.3.4      2017-09-16 [1]
#>  desc          1.2.0      2019-01-21 [1]
#>  devtools      2.0.1.9000 2019-01-29 [1]
#>  digest        0.6.18     2018-10-10 [1]
#>  dplyr         0.8.0      2019-01-31 [1]
#>  evaluate      0.12       2018-10-09 [1]
#>  fs            1.2.6      2018-08-23 [1]
#>  generics      0.0.2      2019-01-20 [1]
#>  glue          1.3.0      2018-07-17 [1]
#>  highr         0.7        2018-06-09 [1]
#>  htmltools     0.3.6      2017-04-28 [1]
#>  knitr         1.21       2018-12-10 [1]
#>  lattice       0.20-38    2018-11-04 [2]
#>  magrittr      1.5        2014-11-22 [1]
#>  Matrix        1.2-15     2018-11-01 [1]
#>  memoise       1.1.0      2017-04-21 [1]
#>  nlme          3.1-137    2018-04-07 [2]
#>  pillar        1.3.1      2018-12-15 [1]
#>  pkgbuild      1.0.2      2018-10-16 [1]
#>  pkgconfig     2.0.2      2018-08-16 [1]
#>  pkgload       1.0.2      2018-10-29 [1]
#>  plyr          1.8.4      2016-06-08 [1]
#>  prettyunits   1.0.2      2015-07-13 [1]
#>  processx      3.2.1      2018-12-05 [1]
#>  ps            1.3.0      2018-12-21 [1]
#>  purrr         0.3.0      2019-01-25 [1]
#>  R2jags      * 0.5-7      2015-08-23 [1]
#>  R2WinBUGS     2.1-21     2015-07-30 [1]
#>  R6            2.3.0      2018-10-04 [1]
#>  Rcpp          1.0.0      2018-11-07 [1]
#>  remotes       2.0.2      2018-10-30 [1]
#>  reshape2      1.4.3      2017-12-11 [1]
#>  rjags       * 4-8        2018-10-19 [1]
#>  rlang         0.3.1      2019-01-08 [1]
#>  rmarkdown     1.11       2018-12-08 [1]
#>  rprojroot     1.3-2      2018-01-03 [1]
#>  sessioninfo   1.1.1      2018-11-05 [1]
#>  stringi       1.2.4      2018-07-20 [1]
#>  stringr       1.3.1      2018-05-10 [1]
#>  testthat      2.0.1      2018-10-13 [1]
#>  tibble        2.0.1      2019-01-12 [1]
#>  tidyr         0.8.2      2018-10-28 [1]
#>  tidyselect    0.2.5      2018-10-11 [1]
#>  TMB           1.7.15     2018-11-09 [1]
#>  usethis       1.4.0.9000 2019-01-29 [1]
#>  withr         2.1.2      2018-03-15 [1]
#>  xfun          0.4        2018-10-23 [1]
#>  yaml          2.2.0      2018-07-25 [1]
#>  source                              
#>  CRAN (R 3.5.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  Github (tidymodels/broom@66411c4)   
#>  Github (bbolker/broom.mixed@fbe9597)
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/cli@94e2fc5)          
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (r-lib/desc@42b9578)         
#>  Github (r-lib/devtools@e4e57aa)     
#>  CRAN (R 3.5.1)                      
#>  Github (tidyverse/dplyr@67b9f4f)    
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (r-lib/generics@d59e6b4)     
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  Github (tidyverse/purrr@240f7b2)    
#>  CRAN (R 3.5.2)                      
#>  CRAN (R 3.5.2)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.2)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  Github (r-lib/usethis@5a0680b)      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.6.0)                      
#>  CRAN (R 3.5.1)                      
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-devel/library

Problems installing

I am having issues trying to install the package, although I am unsure why.

Errors seem related to functions included in JWiley/postMCMCglmm, but installing that didn't resolve the issue.

* installing *source* package 'broom.mixed' ...
** R
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
  converting help for package 'broom.mixed'
    finding HTML links ... done
    augment.ranef.mer                       html  
    brms_tidiers                            html  
Rd warning: C:/Users/Wouter/AppData/Local/Temp/RtmpSuaOsM/devtools37e4c36181f/bbolker-broom.mixed-2dbc9ae/man/brms_tidiers.Rd:85: missing file link 'brms'
    compact                                 html  
    gamlss_tidiers                          html  
    glmmTMB_tidiers                         html  
    glmmadmb_tidiers                        html  
    insert_NAs                              html  
    lme4_tidiers                            html  
Rd warning: C:/Users/Wouter/AppData/Local/Temp/RtmpSuaOsM/devtools37e4c36181f/bbolker-broom.mixed-2dbc9ae/man/lme4_tidiers.Rd:27: missing file link 'coef.merMod'
    mcmc_tidiers                            html  
    nlme_tidiers                            html  
    rstanarm_tidiers                        html  
    unrowname                               html  
** building package indices
** testing if installed package can be loaded
*** arch - i386
Warning: S3 methods 'fixef.MCMCglmm', 'ranef.MCMCglmm' were declared in NAMESPACE but not found
Error: package or namespace load failed for 'broom.mixed' in namespaceExport(ns, exports):
 undefined exports: paramNamesMCMCglmm, ranefLevels, stdranef
Error: loading failed
Execution halted
*** arch - x64
Warning: S3 methods 'fixef.MCMCglmm', 'ranef.MCMCglmm' were declared in NAMESPACE but not found
Error: package or namespace load failed for 'broom.mixed' in namespaceExport(ns, exports):
 undefined exports: paramNamesMCMCglmm, ranefLevels, stdranef
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/Wouter/Documents/R/win-library/3.4/broom.mixed'
In R CMD INSTALL
Installation failed: Command failed (1)

Error using broom::tidy on rxLogisticRegression

Hi,

I am trying to use the broom package with some of the revoscaleR packages. Specifically, I am trying to use broom::tidy with rxLogisticRegression. When trying to do so, I get the following error messages:

Error in as.data.frame.default(x) :
cannot coerce class "c("LogisticRegression", "mlModel")" to a data.frame
Calls: source ... tidy.default -> as.data.frame -> as.data.frame.default
In addition: Warning message:
In tidy.default(logitObj) :
No method for tidying an S3 object of class LogisticRegression , using as.data.frameNo method for tidying an S3 object of class mlModel , using as.data.frame

Is there any way to get around this issue? Thanks!

discuss new defaults

inst/NEWS.Rd now contains the following description, which is my preference for the (default) behaviour of mixed model tidiers. I don't actually understand the use case for which effects="ran_coefs" (the old behaviour) is the desired default. I could see an argument for effects="fixed" (only) rather than effects=c("fixed","ran_pars"), but slightly prefer the latter.

Discuss.


The default behaviour of most mixed-model tidiers has changed/will gradually be changed to the following (description modified from TJ Mahr at <URL: https://github.com/tidyverse/broom/issues/96>):

  • Random effect variances and covariances can be now extracted. ‘effects = "ran_pars"’ returns the standard deviations/correlations of random effects (if ‘scales="sdcor"’) or their variances and covariances (if ‘scales = "varcov"’)
  • Random effects estimates are now extracted with ‘effects = "ran_coefs"’ for the group-level estimates (previously these effects were extracted with ‘tidy(model, "random")’) or ‘effects = "ran_modes"’ for the conditional modes (deviations of the group-level parameters from the population-level estimates)
  • ‘effects’ can take a vector of values (those listed above, plus "fixed" for fixed effects). The default value is ‘effects = c("ran_pars", "fixed")’ which extracts random effect variances/covariances and fixed effect estimates.

tests work in devtools::test() but fail in devtools::check()

don't know what's going on. devtools::test(".") works fine (except for expected warnings) in a clean session, but devtools::check(".")

I suspect it has to do with the fact that some of the same S3 generics defined in both broom and broom.mixed, but I'm pretty mystified. Weakened the dependency on broom (only importing some stuff now), which is probably a good idea in any case, but doesn't seem to fix it.

Not everything fails, just these:

OK: 29 SKIPPED: 1 FAILED: 6

  1. Failure: tidy works on lme4 fits (@test-lme4.R#15)
  2. Failure: tidy works on lme4 fits (@test-lme4.R#16)
  3. Failure: tidy works with more than one RE grouping variable (@test-lme4.R#41)
  4. Error: ran_modes works (@test-lme4.R#79)
  5. Failure: tidy works on nlme/lme fits (@test-nlme.R#14)
  6. Failure: Fit without data in returned structure works when data are given (@test-nlme.R#80)

feature request: supporting Fitting Linear Quantile Mixed Models (`lqmm`) models

# set up
set.seed(123)
library(lqmm)

# data preparation
M <- 50
n <- 10
test <- data.frame(x = runif(n * M, 0, 1), group = rep(1:M, each = n))
test$y <- 10 * test$x + rep(rnorm(M, 0, 2), each = n) + rchisq(n * M, 3)

# model
fit.lqmm <- lqmm::lqmm(
  fixed = y ~ x,
  random = ~ 1,
  group = group,
  data = test,
  tau = 0.5,
  nK = 11,
  type = "normal"
)

# class
class(fit.lqmm)
#> [1] "lqmm"

# summary
summary(fit.lqmm)
#> Call: lqmm::lqmm(fixed = y ~ x, random = ~1, group = group, tau = 0.5, 
#>     nK = 11, type = "normal", data = test)
#> 
#> Quantile 0.5 
#> 
#> Fixed effects:
#>               Value Std. Error lower bound upper bound  Pr(>|t|)    
#> (Intercept) 3.44348    0.63413     2.16915      4.7178 1.743e-06 ***
#> x           9.25833    0.62218     8.00801     10.5087 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> AIC:
#> [1] 2363 (df = 4)

# tidies present?
broom.mixed::tidy(fit.lqmm)
#> Registered S3 methods overwritten by 'broom.mixed':
#>   method         from 
#>   augment.lme    broom
#>   augment.merMod broom
#>   glance.lme     broom
#>   glance.merMod  broom
#>   glance.stanreg broom
#>   tidy.brmsfit   broom
#>   tidy.gamlss    broom
#>   tidy.lme       broom
#>   tidy.merMod    broom
#>   tidy.rjags     broom
#>   tidy.stanfit   broom
#>   tidy.stanreg   broom
#> Error: No tidy method for objects of class lqmm

# glance method present?
broom.mixed::glance(fit.lqmm)
#> Error: No glance method for objects of class lqmm

Created on 2018-11-18 by the reprex package (v0.2.1)

R-version requirement

Is there a reason (e.g. a specific function...) why broom.mixed depends on R >= 3.5? There are still a lot of people around who have R 3.3.x or 3.4.x (or maybe < 3.3) installed, which makes it difficult to import broom.mixed into own packages if you want to reach as many users as possible...

You can close this issue if it's necessary to depend on R >= 3.5, else, could the version requirement be decreased?

version 0.2.0 release

@dmenne @dgrtwo @wpetry @JWiley @alexpghayes (I don't know if this will work for everyone)

I don't know of any release-blocking, or even release-wishlist, items, but would be happy to hear of any (and would be even happier to have people look over the package and see if there are any issues)

feature request: supporting rank-based estimation in random effects nested models

# set up
set.seed(123)
library(rlme)
data(schools)

# model
rlme_model <- rlme::rlme(
  f = y ~ 1 + sex + age + (1 | region) + (1 | region:school),
  data = schools,
  method = "gr"
)
# class
class(rlme_model)
#> [1] "rlme"

# summary
summary(rlme_model)
#> Linear mixed model fit by  GR 
#> Formula:  y ~ 1 + sex + age + (1 | region) + (1 | region:school) 
#> Random effects:
#>  Groups        Name        Variance  
#>  region        (Intercept) 0.14694635
#>  region:school (Intercept) 0.01498658
#>  Residual                  0.81231413
#> 
#> Number of obs:
#> 334 observations, 4 clusters, 11 subclusters
#> 
#> Fixed effects:
#>              Estimate   Std. Error t value    p value    
#>  (Intercept)  0.1560725 0.2685694   0.5811255 0.561155863
#>  sex         -0.2959818 0.1073952  -2.7560058 0.005851197
#>  age          0.2250915 0.1625741   1.3845472 0.166190974
#> 
#> Intra-class correlation coefficients
#>                   Esimates 
#>  intra-cluster    0.1508307
#>  intra-subcluster 0.1662134
#> 
#> cov-var (fixed effects)
#>                             sex           age
#>      7.212951e-02 -0.0002003339 -1.694504e-05
#> sex -2.003339e-04  0.0115337301  9.857307e-04
#> age -1.694504e-05  0.0009857307  2.643034e-02

# tidies present?
broom.mixed::tidy(rlme_model)
#> Registered S3 methods overwritten by 'broom.mixed':
#>   method         from 
#>   augment.lme    broom
#>   augment.merMod broom
#>   glance.lme     broom
#>   glance.merMod  broom
#>   glance.stanreg broom
#>   tidy.brmsfit   broom
#>   tidy.gamlss    broom
#>   tidy.lme       broom
#>   tidy.merMod    broom
#>   tidy.rjags     broom
#>   tidy.stanfit   broom
#>   tidy.stanreg   broom
#> Error: No tidy method for objects of class rlme

# glance method present?
broom.mixed::glance(rlme_model)
#> Error: No glance method for objects of class rlme

Created on 2018-11-18 by the reprex package (v0.2.1)

`component` column for zero-inflation models in Stan

It would be nice if tidy() would also return a component-column for models fitted with brms and zero-inflated component, similar to what is returned for glmmTMB.

library(brms)
library(broom.mixed)

zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv")

m <- brm(
  bf(count ~ child + camper + (1 | persons), 
     zi ~ child + camper + (1 | persons)),
  data = zinb,
  chains = 1, iter = 500,
  family = zero_inflated_poisson()
)

broom.mixed::tidy(m, effects = "fixed")
#> # A tibble: 6 x 6
#>   effect term         estimate std.error conf.low conf.high
#>   <chr>  <chr>           <dbl>     <dbl>    <dbl>     <dbl>
#> 1 fixed  Intercept       1.20     1.01     -1.27      2.97 
#> 2 fixed  zi_Intercept   -0.725    0.762    -2.67      0.495
#> 3 fixed  child          -1.15     0.0888   -1.33     -0.978
#> 4 fixed  camper          0.736    0.0959    0.545     0.925
#> 5 fixed  zi_child        1.88     0.304     1.33      2.49 
#> 6 fixed  zi_camper      -0.827    0.336    -1.47     -0.229

Created on 2018-10-05 by the reprex package (v0.2.1)

update contributor list

Not sure which of the people in broom's DESCRIPTION file are contributors specifically to the mixed-model stuff. Definitely David Robinson, Ben Bolker, Will Petry, Dieter Menne (@dmenne), Josh Wiley, Paul-Christian Buerkner, Benjamin Nutter, Chris Hua (@stillmatic), Jonah Gabry (@jgabry) ...

***  brms_tidiers.R
author dgrtwo
author Paul-Christian Bürkner
***  gamlss_tidiers.R
author dgrtwo
***  lme4_tidiers.R
author bbolker
author Benjamin
author dgrtwo
author Patrick Kennedy
***  mcmc_tidiers.R
author bbolker
author Dave Robinson
author dgrtwo
author jgabry
***  nlme_tidiers.R
author Benjamin
author Chris Hua
author Dieter Menne
***  rstanarm_tidiers.R
author dgrtwo
author jgabry

feature request: supporting linear mixed-effects models under heavy-tailed distributions

# set up
set.seed(123)
library(heavy)
data(dental)

# model
fit <-
  heavy::heavyLme(
    fixed = distance ~ age * Sex,
    random = ~ age,
    groups = ~ Subject,
    data = dental,
    family = Student(df = 4)
  )

# class
class(fit)
#> [1] "heavyLme"

# summary
summary(fit)
#> Linear mixed-effects model under heavy-tailed distributions
#>  Data: dental; Family: Student(df = 5.57571) 
#>  Log-likelihood: -213.6174 
#> 
#> Random effects:
#>  Formula: ~age; Groups: ~Subject 
#>  Scale matrix estimate:
#>             (Intercept) age        
#> (Intercept)  3.99479783            
#> age         -0.23905366  0.04887959
#> Within-Group scale parameter: 0.8829409 
#> 
#> Fixed: distance ~ age * Sex 
#>               Estimate Std.Error Z-value p-value
#> (Intercept)   16.9819   1.6995    9.9922  0.0000
#> age            0.7170   0.1677    4.2765  0.0000
#> SexFemale      0.6798   2.6626    0.2553  0.7985
#> age:SexFemale -0.0678   0.2627   -0.2579  0.7965
#> 
#> Number of Observations: 108 
#> Number of Groups: 27

# tidies present?
broom.mixed::tidy(fit)
#> Registered S3 methods overwritten by 'broom.mixed':
#>   method         from 
#>   augment.lme    broom
#>   augment.merMod broom
#>   glance.lme     broom
#>   glance.merMod  broom
#>   glance.stanreg broom
#>   tidy.brmsfit   broom
#>   tidy.gamlss    broom
#>   tidy.lme       broom
#>   tidy.merMod    broom
#>   tidy.rjags     broom
#>   tidy.stanfit   broom
#>   tidy.stanreg   broom
#> Error: No tidy method for objects of class heavyLme

# glance method present?
broom.mixed::glance(fit)
#> Error: No glance method for objects of class heavyLme

Created on 2018-11-18 by the reprex package (v0.2.1)

`component` argument not recognized for glmmTMB models

library(glmmTMB)
library(broom.mixed)

m1 <- glmmTMB(count~ mined + (1|site), 
              zi=~mined, 
              family=poisson, data=Salamanders)

broom.mixed::tidy(m1, effects = "fixed", component = "cond")
#> # A tibble: 4 x 7
#>   effect component term        estimate std.error statistic  p.value
#>   <chr>  <chr>     <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 fixed  cond      (Intercept)   0.0879     0.233     0.377 7.06e- 1
#> 2 fixed  cond      minedno       1.14       0.246     4.64  3.50e- 6
#> 3 fixed  zi        (Intercept)   1.14       0.235     4.85  1.26e- 6
#> 4 fixed  zi        minedno      -1.74       0.262    -6.63  3.44e-11

broom.mixed::tidy(m1, effects = "fixed", component = "zi")
#> # A tibble: 4 x 7
#>   effect component term        estimate std.error statistic  p.value
#>   <chr>  <chr>     <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 fixed  cond      (Intercept)   0.0879     0.233     0.377 7.06e- 1
#> 2 fixed  cond      minedno       1.14       0.246     4.64  3.50e- 6
#> 3 fixed  zi        (Intercept)   1.14       0.235     4.85  1.26e- 6
#> 4 fixed  zi        minedno      -1.74       0.262    -6.63  3.44e-11

Created on 2018-10-04 by the reprex package (v0.2.1)

Change default value of CI/HDI for Stan-/Bayes-Models?

The authors of rstanarm (see ?rstanarm::posterior_interval) or John Kruschke (see Kruschke JK. Doing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan. 2nd edition. Academic Press, 2015, pp183-85) recommend reporting 90% credible intervals for models with less than 10.000 samples, instead of 95%.

Since the default of modelling functions like brm() or those functions in rstanarm are 4.000 samples, would you say it make sense to set the argument conf.level in tidy() to .9 instead .95?

tidy() ignores monotonic effects in brms models

Paul has published a paper, which describes how to model monotonic effects in brms. These terms (indicated in the formula with mo()) are not shown in the output of tidy() (using broom.mixed 0.2.3). The data resp. the model does not make much sense with the income variable, this is just for demonstration purposes.

library(broom.mixed)
library(brms)

zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv")

income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 250, TRUE), levels = income_options, ordered = TRUE)
zinb$income <- income

m <- brm(
  bf(count ~ child + camper + mo(income) + (1 | persons), 
     zi ~ child + camper + (1 | persons)),
  data = zinb,
  family = zero_inflated_poisson(),
  cores = 4,
  iter = 500,
  chains = 1
)

broom.mixed::tidy(m)
#> # A tibble: 8 x 8
#>   effect  component group  term      estimate std.error conf.low conf.high
#>   <chr>   <chr>     <chr>  <chr>        <dbl>     <dbl>    <dbl>     <dbl>
#> 1 fixed   cond      <NA>   (Interce~    0.998    1.15     -1.63     3.31  
#> 2 fixed   zi        <NA>   (Interce~   -0.787    0.832    -2.72     0.926 
#> 3 fixed   cond      <NA>   child       -1.13     0.0894   -1.31    -0.951 
#> 4 fixed   cond      <NA>   camper       0.637    0.0944    0.450    0.807 
#> 5 fixed   zi        <NA>   child        1.89     0.320     1.28     2.51  
#> 6 fixed   zi        <NA>   camper      -0.857    0.389    -1.58    -0.0490
#> 7 ran_pa~ cond      perso~ sd__(Int~    1.86     1.07      0.684    4.44  
#> 8 ran_pa~ zi        perso~ sd__(Int~    1.77     1.41      0.480    6.05

summary(m)
#>  Family: zero_inflated_poisson 
#>   Links: mu = log; zi = logit 
#> Formula: count ~ child + camper + mo(income) + (1 | persons) 
#>          zi ~ child + camper + (1 | persons)
#>    Data: zinb (Number of observations: 250) 
#> Samples: 1 chains, each with iter = 500; warmup = 250; thin = 1;
#>          total post-warmup samples = 250
#> 
#> Group-Level Effects: 
#> ~persons (Number of levels: 4) 
#>                  Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
#> sd(Intercept)        1.86      1.07     0.68     4.44         83 1.02
#> sd(zi_Intercept)     1.77      1.41     0.48     6.05         97 1.00
#> 
#> Population-Level Effects: 
#>              Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
#> Intercept        1.00      1.15    -1.63     3.31         79 1.00
#> zi_Intercept    -0.79      0.83    -2.72     0.93        163 1.00
#> child           -1.13      0.09    -1.31    -0.95        209 1.00
#> camper           0.64      0.09     0.45     0.81        318 1.00
#> zi_child         1.89      0.32     1.28     2.51        314 1.00
#> zi_camper       -0.86      0.39    -1.58    -0.05        234 1.00
#> moincome         0.83      0.10     0.63     1.01        151 1.00
#> 
#> Simplex Parameters: 
#>              Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
#> moincome1[1]     0.17      0.09     0.03     0.35         74 1.00
#> moincome1[2]     0.06      0.05     0.00     0.18        307 1.00
#> moincome1[3]     0.77      0.09     0.60     0.92        103 1.00
#> 
#> Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample 
#> is a crude measure of effective sample size, and Rhat is the potential 
#> scale reduction factor on split chains (at convergence, Rhat = 1).

Created on 2018-11-04 by the reprex package (v0.2.1)

Levels missing for zero-inflated component of random effects in Stan mixed models

For the conditional model, the levels of the random intercept is shown (coluimn level), however, for the zi-part these values are empty / missing.

library(brms)
library(broom.mixed)

zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv")

m <- brm(
  bf(count ~ child + camper + (1 | persons), 
     zi ~ child + camper + (1 | persons)),
  data = zinb,
  chains = 1, iter = 500,
  family = zero_inflated_poisson()
)

broom.mixed::tidy(m, effects = "ran_vals")
#> # A tibble: 8 x 8
#>   effect   group   term      level estimate std.error conf.low conf.high
#>   <chr>    <chr>   <chr>     <chr>    <dbl>     <dbl>    <dbl>     <dbl>
#> 1 ran_vals persons Intercept 1       -1.28      1.06    -3.80      0.984
#> 2 ran_vals persons Intercept 2       -0.311     1.06    -2.68      1.87 
#> 3 ran_vals persons Intercept 3        0.399     1.06    -2.06      2.67 
#> 4 ran_vals persons Intercept 4        1.29      1.06    -1.15      3.46 
#> 5 ran_vals persons zi        ""       1.33      0.973   -0.549     3.29 
#> 6 ran_vals persons zi        ""       0.342     0.934   -1.56      2.20 
#> 7 ran_vals persons zi        ""      -0.156     0.943   -2.05      1.59 
#> 8 ran_vals persons zi        ""      -1.30      0.958   -3.24      0.676

Created on 2018-10-05 by the reprex package (v0.2.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.