06 May, 2022
How maximize power?
How maximize power?
How do we increase power - without more sites (replicates)
Subreplicates - yet these are not independent
Nested design
How do we increase power…
Block treatments together - yet these are not independent
Randomized complete design
#data.rcb <- read.csv('../data/data.rcb.csv') head(data.rcb)
## y x block ## 1 281.1091 18.58561 Block1 ## 2 295.6535 26.04867 Block1 ## 3 328.3234 40.09974 Block1 ## 4 360.1672 63.57455 Block1 ## 5 276.7050 14.11774 Block1 ## 6 348.9709 62.88728 Block1
library(ggplot2) ggplot(data.rcb, aes(y=y, x=x)) + geom_point() + geom_smooth(method='lm')
library(ggplot2) ggplot(data.rcb, aes(y=y, x=x,color=block))+geom_point()+ geom_smooth(method='lm')
Simple linear regression - wrong
data.rcb.lm <- lm(y~x, data.rcb)
plot(residuals(data.rcb.lm) ~ data.rcb$block)
Simple ANCOVA - wrong
data.rcb.lm1 <- lm(y~x+block, data=data.rcb)
plot(residuals(data.rcb.lm1) ~ data.rcb$block)
\[ \text{Variance-covariance per Block:} \mathbf{V} = \begin{pmatrix} \sigma^2&\rho&\cdots&\rho\\ \rho&\sigma^2&\cdots&\vdots\\ \vdots&\cdots&\sigma^2&\vdots\\ \rho&\cdots&\cdots&\sigma^2\\ \end{pmatrix} \]
library(nlme) data.rcb.lme <- lme(y~x, random=~1|block, data.rcb, method='REML') plot(data.rcb.lme)
plot(residuals(data.rcb.lme, type='normalized') ~ fitted(data.rcb.lme))
plot(residuals(data.rcb.lme, type='normalized') ~ data.rcb$block)
summary(data.rcb.lme)
## Linear mixed-effects model fit by REML ## Data: data.rcb ## AIC BIC logLik ## 458.9521 467.1938 -225.476 ## ## Random effects: ## Formula: ~1 | block ## (Intercept) Residual ## StdDev: 18.10888 8.905485 ## ## Fixed effects: y ~ x ## Value Std.Error DF t-value p-value ## (Intercept) 232.8193 7.823393 53 29.75937 0 ## x 1.4591 0.063789 53 22.87392 0 ## Correlation: ## (Intr) ## x -0.292 ## ## Standardized Within-Group Residuals: ## Min Q1 Med Q3 Max ## -2.09947262 -0.57994305 -0.04874031 0.56685096 2.49464217 ## ## Number of Observations: 60 ## Number of Groups: 6
anova(data.rcb.lme)
## numDF denDF F-value p-value ## (Intercept) 1 53 1452.2883 <.0001 ## x 1 53 523.2164 <.0001
intervals(data.rcb.lme)
## Approximate 95% confidence intervals ## ## Fixed effects: ## lower est. upper ## (Intercept) 217.127551 232.819291 248.511031 ## x 1.331156 1.459101 1.587045 ## ## Random Effects: ## Level: block ## lower est. upper ## sd((Intercept)) 9.597555 18.10888 34.16822 ## ## Within-group standard error: ## lower est. upper ## 7.361788 8.905485 10.772879
vc<-as.numeric(as.matrix(VarCorr(data.rcb.lme))[,1]) vc/sum(vc)
## [1] 0.8052553 0.1947447
library(effects) plot(allEffects(data.rcb.lme, partial.residuals=TRUE))
predict(data.rcb.lme, newdata=data.frame(x=30:40),level=0)
## [1] 276.5923 278.0514 279.5105 280.9696 282.4287 283.8878 285.3469 286.8060 ## [9] 288.2651 289.7242 291.1833 ## attr(,"label") ## [1] "Predicted values"
predict(data.rcb.lme, newdata=data.frame(x=30:40, block='Block1'),level=1)
## Block1 Block1 Block1 Block1 Block1 Block1 Block1 Block1 ## 302.7422 304.2013 305.6604 307.1195 308.5786 310.0377 311.4968 312.9559 ## Block1 Block1 Block1 ## 314.4150 315.8741 317.3332 ## attr(,"label") ## [1] "Predicted values"
lm –> LME
(integrate likelihood across all unobserved levels random effects)
lm –> LME
(integrate likelihood across all unobserved levels random effects)
glm —-………–> GLMM
Not so easy - need to approximate
Penalized quasi-likelihood
Laplace approximation
Gauss-Hermite quadrature
Second-order Taylor series expansion - to approximate likelihood at unobserved levels of random effects
Second-order Taylor series expansion - to approximate likelihood at unobserved levels of random effects
Second-order Taylor series expansion - to approximate likelihood at unobserved levels of random effects
Depends on:
Approximation | Characteristics | Associated inference | R function |
---|---|---|---|
Penalized Quasi-likelihood (PQL) | Fast and simple, accommodates heterogeneity and dependency structures, biased for small samples | Wald tests only | glmmPQL (MASS) |
Laplace | More accurate (less biased), slower, does not accommodates heterogeneity and dependency structures | LRT | glmer (lme4), glmmTMB (glmmTMB) |
Gauss-Hermite quadrature | Even more accurate (less biased), even slower, does not accommodates heterogeneity and dependency structures, cant handle more than 1 random effect | LRT | glmer (lme4)?? *Does not seem to work* |
Markov Chain Monte Carlo (MCMC) | Bayesian, very flexible and accurate, yet very slow and complex | Bayesian credibility intervals, Bayesian P-values | Numerous |
Feature | glmmPQL (MASS) | glmer (lme4) | glmmTMB (glmmTMB) | MCMC |
---|---|---|---|---|
Variance and covariance structures | Yes | - | not yet | Yes |
Overdispersed (Quasi) families | Yes | - | - | Yes |
Mixture families | limited | limited | someYes |
|
Complex nesting | Yes | Yes | Yes | Yes |
Zero-inflation | - | - | Yes | Yes |
Resid degrees of freedom | Between-Within | - | - | - |
Parameter tests | Wald $t$ | Wald $z$ | Wald $z$ | UI |
Marginal tests (fixed effects) | Wald $F$, $\chi^2$ | Wald $F$, $\chi^2$ | Wald $F$, $\chi^2$ | UI |
Marginal tests (Random effects) | Wald $F$,$\chi^2$ | LRT | LRT | UI |
Information criterion | - | AIC | AIC | AIC, WAIC |