pitakakariki / simr

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

no applicable method for 'simulate' applied to an object of class "character" #200

Open RWaisman opened 3 years ago

RWaisman commented 3 years ago

Hi,

I cannot figure out if this is a bug or something I am doing wrong. I am new to using simr, but excited by its capabilities. If only I could figure out how to use it ; )

First time I ran powerSim() everything seemed to work fine. But now it produces errors when I am following the exact same procedure with the same dataset.

The model is targetM = lmer(value ~ defaulttreatmentevaluation + (1 | id), data=melt.targetResults) with default and treatment as 2-level between-subjects factors and evaluation being a before-after within-subjects factor

The data looks like this: head(melt.targetResults) id dv1 cov altPrior default target treatment evaluation value 1 327796 0 9 8 present science antagonistic prior 2 2 934039 5 10 1 present comedy antagonistic prior 2 3 109764 0 10 8 absent comedy antagonistic prior 6 4 245276 3 9 9 present science antagonistic prior 6 5 470476 5 7 8 absent comedy consistent prior 9 6 573650 4 10 7 present science antagonistic prior 8

First run was (as the 3-way interaction is the key effect of interest): powerSim(targetM, test = "defaultpresent:treatmentconsistent:evaluationpost","f", getSimrOption(car::Anova ("III")))

After extending the dataset targetM2 <- extend(targetM, along="id", n=2000) I started getting errors not matter what I do.

Using lastResult()$errors I get "no applicable method for 'simulate' applied to an object of class "character" for all 1000 simulation attempts. If I start from scratch with the original model the same thing occurs.

But if I run: powerSim(targetM, "defaultpresent:treatmentconsistent:evaluationpost") or powerSim(targetM, "defaultpresent") A new error arises: "could not find function "test"" for all 1000 simulations

I can't find anything in your documentation that hints at what might be going on. Any suggestions?

Cheers, Rory

ninawale commented 3 years ago

I'm having a similar problem but with the test function.

I have fit a model using lmer. When I run powerSim(model, fixed("maineffect"), n=100), I get no warnings but 100 errors. lastResult()$errors reports "no applicable method for 'test' applied to an object of class "c('lmerMod', 'merMod')" for all 100 simulations.

This happens no matter which maineffect I specify or whether said effect is an interaction. It also happens irrespective of whether Im doing a non-kosher posthoc power analysis or if i specify the value of that main effect and ask if I have the power to test it.

If I run fcompare rather than fixed, however, it does run. Please help!

pitakakariki commented 3 years ago

If you have tidyverse loaded after simr it might have overwritten some function names. Maybe try simr::fixed instead of fixed?

ninawale commented 3 years ago

Thanks, as soon as I wrote this I saw a past comment wherein you advised that. Sorry!

pitakakariki commented 3 years ago

No worries. The more people I see getting caught by it the more likely I am to fix it.

RWaisman commented 3 years ago

I tried that and go ta new error: Testing 1 scope is not a subset of term labels

RWaisman commented 3 years ago

the code I ran was: powerSim(targetM, simr::fixed("defaultpresent:treatmentconsistent:evaluationpost"))

pitakakariki commented 3 years ago

That might need to be simr::fixed("defaultpresent:treatmentconsistent:evaluationpost", "z").

RWaisman commented 3 years ago

that works!!! Thank you : )