Error with wp.poisson function for Power Analysis

I am trying to do a power analysis to determine the sample size for Poisson glm regression that I plan to do once I have my experiment data.
The only function that I have been able to find to calculate sample size for Poisson is wp.poisson() in the WebPower package. However, when I run the function (below) I get the resulting error:

wp.poisson(n = NULL, 
           exp0 = 5.0345, 
           exp1 = 1.5862, 
           alpha = 0.05,
           power = 0.8, 
           alternative = "two.sided",
           family = "Poisson", 
           parameter = 1)

Error in uniroot(function(n) eval(p.body) - power, c(2 + 1e-10, 1e+07)) : f.lower = f(lower) is NA

Can someone help me figure this out?
Alternatively, does anyone know how else to do power analysis to determine sample size for a Poisson regression? 

Thank you.
library(WebPower)
library(purrr)
library(plotly)

params <- expand.grid(exp0_v = seq.default(from=0,to=2,by=.2),
            exp1_v = seq.default(from=0,to=2,by=.2))



params$n_result <- map2_dbl(.x=params$exp0_v,
     .y=params$exp1_v,
     .f=~tryCatch(wp.poisson(n = NULL, 
                             exp0 = .x, 
                             exp1 = .y, 
                             alpha = 0.05,
                             power = 0.8, 
                             alternative = "two.sided",
                             family = "Poisson", 
                             parameter = 1)$n
                  , error = function(e) NA)
   
)
plot_ly(data=params,
        x=~exp0_v,
        y=~exp1_v,
        z=~n_result, 
        type="scatter3d", mode="markers", color=~n_result,
        text=~paste0("exp0 : " ,exp0_v, "\n",
                     "exp1 : " ,exp1_v, "\n",
                     "n_result : " ,n_result, "\n"),
        hoverinfo="text")

with the other params you set, values above 1 for exp1 will give NA values due to infinities in the calculations

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Thank you for sharing!