Open djjohnson89 opened 5 years ago
The error messages I am getting are:
lastResult()$errors
stage index message
1 Simulating 1 new levels detected in newdata
2 Simulating 2 new levels detected in newdata
3 Simulating 3 new levels detected in newdata
I believe this may refer to my predictors. tRace and race are contrast coded with Whites as the reference group and sex is effects coded (women = -.5, men = .5). How can I stop the simulations from creating new levels that don't exist?
After looking at some of the other problems logged in this forum, I'm not sure this is just a contrast issue. I am running rsim version 1.04. This problem occurs whether I have contrasts in my model (race and sex) or only a single continuous predictor.
I usually see that error when there's missing data.
You could try e.g. mdata <- na.omit(subset(df, tSex == "male"))
and see if that fixes things.
If that doesn't work, you might need to use droplevels
instead of na.omit
.
When running the very simple model:
sM1 <- lmer(strong ~ tRace +
(1|target),
data = na.omit(subset(df, tSex == "male")),
REML = F)
powerSim(sM1, test = fixed(xname = "tRace", method = c("z")), nsim = 3)
lastResult()$errors
stage index message
1 Testing 1 subscript out of bounds
2 Testing 2 subscript out of bounds
3 Testing 3 subscript out of bounds
I get the same result when I use drop levels instead of na.omit. This issue is happening even when I run a super simple model with only one continuous predictor (no factors):
sM2 <- lmer(strong ~ tBicep +
(1|target),
data = subset(df, tSex == "male"),
REML = F)
When I run the powerSim()
function I get the same errors. That is, I get a "new levels detected" when I use my data, and "subscript out of bounds" when I use na.omit()
.
If you're using a z-test you'll need to specify the variable name from fixef(sM1)
, not just "tRace"
. It will lokk something like "tRaceabc"
.
I'm attempting to conduct an observed power calculation for the following model:
Which returns the following result:
However, when I go to calculate the observed power for my data, I keep getting the following:
This happens even when I greatly simplify the model:
When I run powerSim() I get the same error for the simpler model:
In the full model, I get this error regardless of what predictor I am trying to measure observed power for. This clearly is not right. What am I missing here? Thanks.