Ken Kelley
2011-Sep-20 14:28 UTC
[Rd] The boot Package with bca Intervals and Inf and NaN Values in an Automated Function [mediation()]
Hi everyone, I use the boot package within the MBESS package to automate much of the hard part for folks interested in performing a (simple) mediation model. The function mediation() works well, except for a (probably) unrealistic artificial data set. When I apply the bootstrap I sometimes get: Error in t.star[r, ] <- res[[r]] which is (I think) due to Inf and -Inf and NaN values produced for some of the estimates in the bootstrap resamples. Here are my warnings> warnings()Warning messages: 1: In sqrt((1 - R2.Y_XM) * ((N - 1) * Cov.Matrix[3, 3]/(N - ... : NaNs produced 2: In max(abs(b.contained)) : no non-missing arguments to max; returning -Inf 3: In max(abs(From.b)) : no non-missing arguments to max; returning -Inf 4: In max(abs(From.a)) : no non-missing arguments to max; returning -Inf 5: In sqrt((1 - R2.Y_XM) * ((N - 1) * Cov.Matrix[3, 3]/(N - ... : NaNs produced 6: In max(abs(b.contained)) : no non-missing arguments to max; returning -Inf 7: In max(abs(From.b)) : no non-missing arguments to max; returning -Inf 8: In max(abs(From.a)) : no non-missing arguments to max; returning -Inf 9: In max(abs(b.contained)) : no non-missing arguments to max; returning -Inf 10: In max(abs(From.b)) : no non-missing arguments to max; returning -Inf 11: In max(abs(From.a)) : no non-missing arguments to max; returning -Inf and here is what boot.out looks like: Bootstrap Statistics : original bias std. error t1* 0 0.01784141 0.030664717 t2* 0 0.00522446 0.009407206 t3* 0 0.01530606 0.026118581 t4* 0 0.10293090 0.132874564 t5* 0 Inf NaN t6* 0 Inf NaN t7* 0 0.06200062 0.069837762 t8* NaN NaN 0.165104486 t9* 0 0.01550669 0.026480612 t10* 0 0.01653285 0.029406830 t11* Inf -Inf 10.806967364 t12* 0 0.05329459 0.074168364 t13* 0 0.06153211 0.081591660 t14* 0 0.10558389 0.136462038 The original estimates of 0, NaN or Inf are correct for this particular set of data (which is artificial for testing purposes). I'm wondering if there is an easy workaround (e.g., to tell boot to ignore NaN, etc.). Alternatively, I could make modifications to the mediation() function in the MBESS package. The idea of the function is to automate much of the hard part for folks interested in a simple mediation model (i.e., so that non R users can easily use the function). However, I'm not sure exactly what I should have mediation() do so that an extreme data set does not produce the problem when coupled with boot. I thought about removing the rows from boot.out$t with NaN and then changing boot.out$R to reflect the reduced number of rows, but I wasn't sure that was such a good idea. The NaNs, by the way, come from dividing 0 by 0. I didn't provide example code because the mediation() function I'm using is not the released version. However, I can send the updated mediation() function to whomever if interested (email me off list for the updated function). Any thoughts on this would be most welcomed! Thanks, Ken