[R-sig-ME] Should I use full models when using Powersim?

Chi Zhang Ch|@Zh@ng @end|ng |rom UGent@be
Sat Feb 16 14:52:47 CET 2019

Dear all,

I tried using powersim from R package simr to estimate the number of participants that I need for an experiment. I performed the simulation based on the data from my pilot study. The model I used is sketched below:

fit <- glmer(B ~ a+b+a:b
             (1+a+b+a:b|Subject) +
           family = binomial(link="logit"),
           data = data,
           control = glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=50000),
                                  tol = .0001))

in which Subject and Item mean the distinct id of subjects and items from the pilot study. I want to know test how the power of the interaction term (a:b) changes with the growth of the number of participants. The code I am using is:

fit2<- extend(fit, along="Subject", n = 84)
sim <- powerCurve(fit2, test = fcompare(~a+b), along = "Subject", breaks=c(48,60,72,84), nsim = 5000)

But the results of the simulation was rather bizarre. To begin with, the power of the interaction grew smaller when the number of participants increased from 72 to 84, which I believe is incompatible with the normal observation that the power increases with the number of participants. Second, I tried using the full random model to perform the simulation, but it is really slow (it took me weeks to get just one result). I was wondering if I can use a simpler random model to perform the simulation.

To reiterate my question: first, why my simulated power decreased with the increase of the number of participants? Is there something wrong with my code? Second, can I use a simpler random model for the simulation in order to save time? Thanks in advance!


Chi Zhang

Chi Zhang

PhD Student
Department of Experimental Psychology
Ghent University
Henri Dunantlaan 2, B-9000 Gent, Belgium
Tel: +32 465386530
E-mail: chi.zhang using ugent.be

From: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> on behalf of r-sig-mixed-models-request using r-project.org <r-sig-mixed-models-request using r-project.org>
Sent: Saturday, February 16, 2019 12:00
To: r-sig-mixed-models using r-project.org
Subject: R-sig-mixed-models Digest, Vol 146, Issue 11

Send R-sig-mixed-models mailing list submissions to
        r-sig-mixed-models using r-project.org

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
        r-sig-mixed-models-request using r-project.org

You can reach the person managing the list at
        r-sig-mixed-models-owner using r-project.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of R-sig-mixed-models digest..."

Today's Topics:

   1. gls() funcion after R upgrade (Fabio Fanoni)
   2. Help with: Multivariate models with binary variables and
      variables with zipoisson distribution (Stacey Hannebaum)
   3. Teaching Assistants for advanced multilevel modeling at ICPSR
      (Poe, John)


Message: 1
Date: Mon, 11 Feb 2019 08:40:28 +0000
From: Fabio Fanoni <fabio.fanoni using popso.it>
To: "r-sig-mixed-models using r-project.org"
        <r-sig-mixed-models using r-project.org>
Subject: [R-sig-ME] gls() funcion after R upgrade
Message-ID: <d0cd3fe9653e44dcbdb782bb8af4094a using popso.it>
Content-Type: text/plain; charset="utf-8"

Dear all,

I have been using the package nlme for about a year through the software R

Recently, following an update of R (and the corresponding nlme package), in some situations the gls() function does not work.

The following lines of code


with the old version of R returns the following output:

Generalized least squares fit by maximum likelihood
  Model: as.formula(f)
  Data: db
  Log-likelihood: -36.13853

      ITOD      EU_CH
-0.3138869 -0.5010393

Correlation Structure: ARMA(2,3)
Formula: ~1
 Parameter estimate(s):
       Phi1        Phi2      Theta1      Theta2      Theta3
 0.50054107 -0.07357577  0.91847373  0.66706344  0.51689285
Variance function:
Structure: Power of variance covariate
Formula: ~fitted(.)
 Parameter estimates:
Degrees of freedom: 71 total; 69 residual
Residual standard error: 0.4077908

while with the new one version of R ends with the following error message

Error in `coef<-.corARMA`(`*tmp*`, value = value[parMap[, i]]) :
  NA/NaN/Inf in foreign function call (arg 1)

here are the parameters of the old version of R

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows >= 8 x64 (build 9200)

[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] nlme_3.1-128

loaded via a namespace (and not attached):
[1] tools_3.3.2     grid_3.3.2      lattice_0.20-34

and the correspondents of the new one

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] nlme_3.1-137

loaded via a namespace (and not attached):
[1] compiler_3.5.2  tools_3.5.2     grid_3.5.2      lattice_0.20-38

The data used are shown below

I wonder if someone could help me to solve this problem.

Best regards,

Fabio Fanoni


Fabio Fanoni
Piazza Garibaldi 16
23100 Sondrio (SO)
Banca Popolare di Sondrio
Tel. +390342528920
fabio.fanoni using popso.it<mailto:fabio.fanoni using popso.it>

AVVERTENZE LEGALI - I contenuti di questo messaggio, proveniente da un indirizzo di posta elettronica aziendale della Banca Popolare di Sondrio, e gli eventuali allegati possono essere letti e utilizzati, per esigenze lavorative, da chi opera alle dipendenze o per conto della stessa, o ? comunque cointeressato nell'inerente relazione d'affari. Le dichiarazioni, ivi contenute, non impegnano contrattualmente la Banca Popolare di Sondrio se non nei limiti di quanto eventualmente previsto in accordi opportunamente formalizzati. Se il messaggio ? stato ricevuto per errore ce ne scusiamo, pregando di segnalare ci? al mittente e poi di distruggerlo senza farne alcun uso poich? l'utilizzo senza averne diritto ? vietato dalla legge e potrebbe costituire reato.

DATI SOCIETARI - BANCA POPOLARE DI SONDRIO - Societ? cooperativa per azioni - Fondata nel 1871
Sede sociale e direzione generale: I - 23100 SONDRIO SO - piazza Garibaldi, 16
Indirizzo Internet: http:[doppiabarra]www[punto]popso[punto]it - E-mail: info[chiocciola]popso[punto]it
Iscritta al Registro delle Imprese di Sondrio al n. 00053810149, all'Albo delle Banche al n. 842, all'Albo delle Societ? Cooperative al n. A160536 Capogruppo del Gruppo bancario Banca Popolare di Sondrio, iscritto all'Albo dei Gruppi bancari al n. 5696.0 Aderente al Fondo Interbancario di Tutela dei Depositi e al Fondo Nazionale di Garanzia - Codice fiscale e partita IVA: 00053810149
Capitale sociale: EUR 1.360.157.331 - Riserve: EUR 947.325.264 (Dati approvati dall'Assemblea dei soci del 29 aprile 2017).

N.B. I "filtri antivirus" e "antispam" in uso su molti sistemi di posta elettronica possono talvolta ritardare o impedire, in tutto o in parte, il recapito dei messaggi. In tali casi, salvo verifica di avvenuta ricezione, pu? essere necessario modificare i contenuti o le modalit? d'invio.

        [[alternative HTML version deleted]]


Message: 2
Date: Fri, 15 Feb 2019 14:25:09 -0600
From: Stacey Hannebaum <stacey-hannebaum using utulsa.edu>
To: r-sig-mixed-models using r-project.org
Subject: [R-sig-ME] Help with: Multivariate models with binary
        variables and variables with zipoisson distribution
        <CAFtRfJXA5jOSX0n343Zs_wcyXnC1Dy3iw06GV513Li7GxUx8nw using mail.gmail.com>
Content-Type: text/plain; charset="utf-8"


I am trying to build a multivariate model to test for associations between
individual variation in behavioral and other traits. Essentially, I want to
derive two calculations from the model: (1) the repeatability of each of
the three traits within individuals and (2) the correlation between each
pair of traits and between each trait and fitness and trappability (the
latter two have one value per individual).
I have been working on this for some time and have reached a standstill.
Here are the main issues I am facing. Any suggestions would be very
(1) How should a binary variable be modelled? For now, I have modelled it
as Gaussian (with the assumption that 0s and 1s are drawn from some
underlying Gaussian process) so that I can calculate correlations but I
don’t know if this is reasonable. Any thoughts?
(2) I tried to run the below model but received the following error:
Error in priorformat(if (NOpriorG) { :
  V is the wrong dimension for some prior$G/prior$R elements
I am sure it has to do with modelling CHARGES as zipoisson - I think I need
to specify the structure for modelling the 0’s but I don’t know where to
start with this.

Below are the variables of interest in case this is useful to know:
logitTAPERETURN: logit-transformed latency to enter a nest once a novel
stimulus was applied / total possible time allowed for trial; trials were
terminated after 5 minutes whether or not bird entered nest; multiple
trials per individual.
CHARGES: number of times an individual attacked the novel stimulus (count
data with many zeros); multiple trials per individual. This could be
expressed as a rate (number of charges / latency to enter nest) but I
decided to model length of trial as a predictor variable using log(latency
to enter nest); trial repeated multiple times per subject
STATUSAFTER: whether the bird stayed in the nest or fled from the nest
CAPTURES: number of times an individual was captured (count data with many
ones and no zeros); only one value per individual
RELFITNESS: number of fledglings for individual / mean number of fledglings
across all individuals; only one value per individual

prior_tr_c_sa_nc_f =
list(G=list(G1=list(V=diag(c(1,1,1,0.0001,0.0001),5,5),nu=1.002, fix = 4)),

I fixed CAPTURES and RELFITNESS because there is not within-individual
variation in these variables.

mcmc_tr_c_sa_nc_f_us <- MCMCglmm(cbind(logitTAPERETURN, CHARGES,
                                            at.level(trait,1):(COLSIZE) +

at.level(trait,1):(TAPETRIALNUM) +

at.level(trait,1):(TAPENESTSTATUS) +
                                            at.level(trait,2):(COLSIZE) +

at.level(trait,2):(stTAPERETURN) +
                                            at.level(trait,2):(stTAPETEMP) +

at.level(trait,3):(stALARMTRIALNUM) +

at.level(trait,3):(stALARMWINDSP) +

at.level(trait,3):(STATUSBEFORE) +
                                            at.level(trait,4):(COLSIZE) +
                                            at.level(trait,5):(COLSIZE) +

at.level(trait,5):(stCLUTCHSIZE) - 1,
                                          random =~ us(trait):BAND,
                                          rcov =~ us(trait):units,
                                          family =
                                          prior = prior_tr_c_sa_nc_f,
                                          verbose = TRUE,
                                          data =

Thank you,

Stacey Hannebaum
Postdoctoral Research Associate

        [[alternative HTML version deleted]]


Message: 3
Date: Fri, 15 Feb 2019 17:46:27 -0600
From: "Poe, John" <jdpo223 using g.uky.edu>
To: r-sig-mixed-models <r-sig-mixed-models using r-project.org>
Subject: [R-sig-ME] Teaching Assistants for advanced multilevel
        modeling at ICPSR
        <CAFW8BypZZqASQ7zdBCYFS3zBa04DPWtWebHjUVoF4cg0RXgPbg using mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I'm looking for recommendations on potential teaching assistants for my
4-week advanced multilevel modeling course at the ICPSR summer program in
Ann Arbor, Michigan. If you know of advanced graduate students or postdocs
who might be qualified and interested please let me know off the listserv
or have them email me directly. It's a great program and Ann Arbor is an
absolutely lovely place to spend some time in the summer.

The class pulls from econometrics,  biostatistics, and psychometrics and
covers both MLE and Bayesian multilevel modeling. I don't expect anyone to
be comfortable with everything so they'd need to be willing to go through
the material with me in an informal readings bootcamp before the class to
fill in gaps.

You can find last year's syllabus here:

        [[alternative HTML version deleted]]


Subject: Digest Footer

R-sig-mixed-models mailing list
R-sig-mixed-models using r-project.org


End of R-sig-mixed-models Digest, Vol 146, Issue 11

More information about the R-sig-mixed-models mailing list