mshafieek / ADS-Missing-data-social-network

ADS master thesis
MIT License
0 stars 1 forks source link

I have a problem and I used the reprex package to illustrate it. #1

Open gerkovink opened 1 year ago

gerkovink commented 1 year ago

The following problem is illustrated by the reprex package

library(mice, warn.conflicts = FALSE)
library(magrittr)
set.seed(123)
imp <- mice(nhanes, printFlag = FALSE)
fit <- with(imp, lm(age ~ bmi))

# regular calculation
pool(fit) %T>% 
  print %>% summary()
#> Class: mipo    m = 5 
#>          term m    estimate        ubar            b           t dfcom       df
#> 1 (Intercept) 5  3.85793713 1.101684619 0.1435955094 1.273999230    23 16.93708
#> 2         bmi 5 -0.07826576 0.001498793 0.0002086205 0.001749137    23 16.64170
#>         riv    lambda       fmi
#> 1 0.1564101 0.1352549 0.2220023
#> 2 0.1670308 0.1431246 0.2303752
#>          term    estimate  std.error statistic       df     p.value
#> 1 (Intercept)  3.85793713 1.12871574  3.417988 16.93708 0.003292004
#> 2         bmi -0.07826576 0.04182269 -1.871371 16.64170 0.078980518

# custom calculation
pool(fit, 
     rule = "reiter2003", 
     custom.t = ".data$b + .data$b/m", 
     custom.df = ".data$m - 1") %T>% 
  print %>% summary()
#> Class: mipo    m = 5 
#>          term m    estimate        ubar            b            t dfcom df
#> 1 (Intercept) 5  3.85793713 1.101684619 0.1435955094 0.1723146113    23  4
#> 2         bmi 5 -0.07826576 0.001498793 0.0002086205 0.0002503446    23  4
#>         riv lambda fmi
#> 1 0.1564101     NA  NA
#> 2 0.1670308     NA  NA
#>          term    estimate  std.error statistic df      p.value
#> 1 (Intercept)  3.85793713 0.41510795  9.293817  4 0.0007457218
#> 2         bmi -0.07826576 0.01582228 -4.946554  4 0.0077803039

# another custom calculation
outsideoffunction <- 14
Rubin_original <- "(.data$m-1)*(1 + (1/((1 + 1 / .data$m) * .data$b / .data$ubar)))^2"
pool(fit, 
     rule = "reiter2003", 
     custom.t = "outsideoffunction", 
     custom.df = "Rubin_original")  %T>% 
  print %>% summary()
#> Class: mipo    m = 5 
#>          term m    estimate        ubar            b  t dfcom
#> 1 (Intercept) 5  3.85793713 1.101684619 0.1435955094 14    23
#> 2         bmi 5 -0.07826576 0.001498793 0.0002086205 14    23
#>                                                                   df       riv
#> 1 (.data$m-1)*(1 + (1/((1 + 1 / .data$m) * .data$b / .data$ubar)))^2 0.1564101
#> 2 (.data$m-1)*(1 + (1/((1 + 1 / .data$m) * .data$b / .data$ubar)))^2 0.1670308
#>   lambda fmi
#> 1     NA  NA
#> 2     NA  NA
#> Error in pt(abs(statistic), pmax(x$df, 0.001), lower.tail = FALSE): Non-numeric argument to mathematical function

Created on 2023-04-26 with reprex v2.0.2

gerkovink commented 1 year ago

Hi, @gerkovink. Nice issue. I'll look at it