strengejacke / sjstats

Effect size measures and significance tests
https://strengejacke.github.io/sjstats
189 stars 21 forks source link

feature request: adding support for `"svyolr"` objects in `sjstats::p_value` #61

Closed IndrajeetPatil closed 5 years ago

IndrajeetPatil commented 5 years ago
# setup
set.seed(123)
library(survey)
#> Loading required package: grid
#> Loading required package: Matrix
#> Loading required package: survival
#> 
#> Attaching package: 'survey'
#> The following object is masked from 'package:graphics':
#> 
#>     dotchart
data(api)

# preparing data
dclus1 <- svydesign(
  id =  ~ dnum,
  weights =  ~ pw,
  data = apiclus1,
  fpc =  ~ fpc
)
dclus1 <- update(dclus1, mealcat = cut(meals, c(0, 25, 50, 75, 100)))

# model
m <- svyolr(mealcat ~ avg.ed + mobility + stype, design = dclus1)

# class
class(m)
#> [1] "svyolr"

# summary
summary(m)
#> Call:
#> svyolr(mealcat ~ avg.ed + mobility + stype, design = dclus1)
#> 
#> Coefficients:
#>               Value Std. Error   t value
#> avg.ed   -2.6999217 1.13422434 -2.380412
#> mobility  0.0325042 0.02065336  1.573797
#> stypeH   -1.7574715 0.69953393 -2.512346
#> stypeM   -0.6191463 0.30964416 -1.999541
#> 
#> Intercepts:
#>                  Value   Std. Error t value
#> (0,25]|(25,50]   -8.8579  3.6862    -2.4030
#> (25,50]|(50,75]  -6.5865  3.1089    -2.1186
#> (50,75]|(75,100] -4.9249  2.8634    -1.7200
#> (26 observations deleted due to missingness)

# tidy output
broom::tidy(m)
#> # A tibble: 7 x 5
#>   term             estimate std.error statistic coefficient_type
#>   <chr>               <dbl>     <dbl>     <dbl> <chr>           
#> 1 avg.ed            -2.70      1.13       -2.38 coefficient     
#> 2 mobility           0.0325    0.0207      1.57 coefficient     
#> 3 stypeH            -1.76      0.700      -2.51 coefficient     
#> 4 stypeM            -0.619     0.310      -2.00 coefficient     
#> 5 (0,25]|(25,50]    -8.86      3.69       -2.40 zeta            
#> 6 (25,50]|(50,75]   -6.59      3.11       -2.12 zeta            
#> 7 (50,75]|(75,100]  -4.92      2.86       -1.72 zeta

# extracting p-values using `sjstats`
sjstats::p_value(m)
#> Error in stats::coef(summary(fit))[, 4]: subscript out of bounds

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