pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
68 stars 19 forks source link

PowerCurve plot error Arrows #245

Open Trebicky opened 1 year ago

Trebicky commented 1 year ago

Following the Simr examples and https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.12504 I fitted a model and tried extending it along participants (from original N=21, nrow~1500).

While potting powercurve I got a strange Error warning (see below). Also, see the print outcome of the extended powercurve (7 and 9 after 62). The issue remains regardless the N to which I try extending or nsim value. Breaks do not seem to matter.

Extended_Atr_AntiBodies <- extend(Atr_AntiBodies, along="target", n=75) pc_Extended_Atr_AntiBodies <- powerCurve(Extended_Atr_AntiBodies, along="target", breaks=c(5,15,30,45,60,75), nsim=50, progress=TRUE) print(pc_Extended_Atr_AntiBodies) plot(pc_Extended_Atr_AntiBodies)

print(pc_Extended_Atr_AntiBodies) Power for predictor 'Anti_HAV_3_Anti_HAV_1', (95% confidence interval), by largest value of target: 11: 1.00% ( 0.03, 5.45) - 219 rows 19: 11.00% ( 5.62, 18.83) - 827 rows 26: 14.00% ( 7.87, 22.37) - 1421 rows 33: 20.00% (12.67, 29.18) - 2015 rows 40: 20.00% (12.67, 29.18) - 2619 rows 48: 24.00% (16.02, 33.57) - 3213 rows 55: 27.00% (18.61, 36.80) - 3809 rows 62: 32.00% (23.02, 42.08) - 4413 rows 7: 38.00% (28.48, 48.25) - 5007 rows 9: 36.00% (26.64, 46.21) - 5601 rows

Time elapsed: 5 h 26 m 6 s

plot(pc_Extended_Atr_AntiBodies) Error in arrows(c("11", "19", "26", "33", "40", "48", "55", "62", "7", : invalid first argument

Any suggestion on how to resolve this?

pitakakariki commented 1 year ago

It does look like it's sorting the participant numbers alphabetically rather then numerically. I'll see if I can find a workaround.

Trebicky commented 1 year ago

It does not seem like that's it. Based on the rows and better percentage, it seems the "7" should be seventy-something.

The same issue held even when I tried along N=50. It went to 40 and then 5.

I would appreciate the help here.

pitakakariki commented 1 year ago

Simplest workaround for now is to set target to numeric.

Trebicky commented 1 year ago

I am R novice. How do you do so, setting target to numeric?

Thanks!

čt 1. 9. 2022 v 10:54 odesílatel Peter Green @.***> napsal:

Simplest workaround for now is to set target to numeric.

— Reply to this email directly, view it on GitHub https://github.com/pitakakariki/simr/issues/245#issuecomment-1233966921, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANG47BEI27DIC6SG7KCWVRDV4BVM5ANCNFSM6AAAAAAQAMHPL4 . You are receiving this because you authored the thread.Message ID: @.***>

Trebicky commented 1 year ago

Ahh, I see now in the dataset, never mind. Thanks, I'll try and post the result.

čt 1. 9. 2022 v 11:09 odesílatel Vít Třebický @.***> napsal:

I am R novice. How do you do so, setting target to numeric?

Thanks!

čt 1. 9. 2022 v 10:54 odesílatel Peter Green @.***> napsal:

Simplest workaround for now is to set target to numeric.

— Reply to this email directly, view it on GitHub https://github.com/pitakakariki/simr/issues/245#issuecomment-1233966921, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANG47BEI27DIC6SG7KCWVRDV4BVM5ANCNFSM6AAAAAAQAMHPL4 . You are receiving this because you authored the thread.Message ID: @.***>

Trebicky commented 1 year ago

It works now. So the issue really was that the column which I tried to extend (along) was strings, not numeric values. Thank you for helping me out.

XiFengxiaoxu commented 11 months ago

i found another simple way to solve it, you can use: pc_Extended_Atr_AntiBodies$xval <- pc_Extended_Atr_AntiBodies$nlevels and then plot again. @pitakakariki