4.5 GxE

squid_data <- simulate_population(
  parameters = list(
    animal = list(
      names = c("G_int","G_slope"),
      mean = c(0,0), 
      vcov = matrix(c(1,0.3,0.3,0.5),ncol=2,nrow=2,byrow=TRUE),
      beta = c(1,0)
    ),
    observation= list(
      names = c("environment"),
      vcov = c(0.2)
    ), 
    residual = list(
      names = c("residual"),
      vcov = c(0.5)
    ),
    interactions=list(
      names = "G_slope:environment",
      beta = 1
    )
  ),
  data_structure=rbind(ped,ped,ped,ped,ped),
  pedigree = list(animal=ped)
)

data <- get_population_data(squid_data)
library(lme4)
short_summary <- function(x) print(summary(x), correlation=FALSE, show.resids=FALSE, ranef.comp = c("Variance"))

short_summary(lmer(y ~ environment + (1+environment|animal),data))
## Linear mixed model fit by REML ['lmerMod']
## Formula: y ~ environment + (1 + environment | animal)
##    Data: data
## 
## REML criterion at convergence: 66750.8
## 
## Random effects:
##  Groups   Name        Variance Cov 
##  animal   (Intercept) 0.9920       
##           environment 0.5068   0.30
##  Residual             0.4955       
## Number of obs: 24590, groups:  animal, 4918
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.02510    0.01497   1.677
## environment  0.98595    0.01580  62.386