[R] LMER - generate data and define model (2 fixed effects and 1 random effect or 1 fixed effect and 2 random effects)

Rosa Oliveira rosita21 at gmail.com
Tue Aug 11 01:44:22 CEST 2015


 

###############################################################################

# Clear memory and set the working directory and the seed

###############################################################################

rm(list = ls())

setwd("/Dropbox/LMER/R ")

set.seed(7010)

###############################################################################

# Load up needed packages and do a require

###############################################################################

# install.packages("gdata")



library(nlme)

library(lme4)



nsample                                       = 1000                    # Number of subjects

n.longitudinal.observations  = 5                                  # number of observations per subject



###############################################################################

# Set the other parameters

###############################################################################

id.pat                       = rep(seq(1:nsample), each =n.longitudinal.observations)

time                         = rep(seq(1:n.longitudinal.observations)-1, nsample)

age                          = rnorm(nsample, mean = 36, sd = .8)
id.age                      = rep(seq(1: n.longitudinal.observations), each =age)





############################################################################### MODEL WITHOUT AGE

boldBeta_individual_blup = coef(lmer(yy~1+time+(time|id.pat)   ))$id.pat   #mixed model





############################################################################### MODEL WITH AGE

boldBeta_individual_blup = coef(lmer(yy~1+age+time+(time|id.pat)   ))$id.pat   #mixed model



Dear all,





I’m trying to use LMER in my simulation problem, and I’m having problems ate the very begging L I’m new in LMER. Can you please help me?





1st problem:

how do I generate age so I can use it as a fixed factor?

2nd problem:

how do I insert age as a fixed factor?

3rd problem:

 what if I wanted to insert a 2nd random effect based on age?



Best,

RO



Atenciosamente,
Rosa Oliveira

-- 
____________________________________________________________________________


Rosa Celeste dos Santos Oliveira, 

E-mail: rosita21 at gmail.com
Tlm: +351 939355143 
Linkedin: https://pt.linkedin.com/in/rosacsoliveira
____________________________________________________________________________
"Many admire, few know"
Hippocrates



More information about the R-help mailing list