pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
70 stars 20 forks source link

Error printing power curve #108

Closed sho-87 closed 6 years ago

sho-87 commented 6 years ago
model <- lmer(y ~ a + b + c + d + d*condition + b*condition + (1+b|id), data=df, REML=F)
fixef(model)["b:condition1"] <- -0.1
pc <- powerCurve(model, test=fixed("b:condition1", "z"), nsim=10)

condition and id are both factors

When I run the code above and try to print(pc) I get the following error:

Power for predictor 'b:condition1', (95% confidence interval),
by largest value of a:
Error in sprintf("%7i: ", x$xval[i]) : 
  invalid format '%7i'; use format %f, %e, %g or %a for numeric objects

plot(pc) works fine, but printing doesnt seem to work. Any idea about whats causing this?

pitakakariki commented 6 years ago

If you need a workaround, summary(pc) ought to still work.

The code assumes that the "along" variable is an integer, and falls over when it's not. It's kind of a mystery that no one found this earlier! Thanks for the bug report.

sho-87 commented 6 years ago

summary(pc) seems to give some information, but I was looking at this paper and looking at the example output there print(pc) appears to have an additional piece of information that is missing from summary(pc) which is the number of rows of data

Im a bit confused about what power curves are intended to show (or maybe Im misusing it). What I want to know is what sample size is required to achieve 80% power. Sample size in my case is given by id (each id is a person). How does largest value of a relate to sample size in this case?

pitakakariki commented 6 years ago

The idea is to have the x-axis for the power curve in sensible units. For example, if you have multiple observations per person, it's more useful to know how many people rather than how many observations in total.

In your case you might want to use along="id" as an argument to powerCurve. The default is the first fixed effect (i.e. a) but as you've noted that probably doesn't make sense for what you're trying to do.

pitakakariki commented 6 years ago

The printing bug is fixed in the github version, but it shouldn't be as issue if id is a factor.

sho-87 commented 6 years ago

perfect, the github version prints correctly now, thanks!