Dear list

I need your help: Execuse me for my limited R knowledge.

#example data set
set.seed (134)
lm=c(1:4)

block = c(rep(lm,6))

gen <- c(rep(1, 4), rep(2, 4), rep(3, 4), rep(4, 4),rep(5, 4),rep(6, 4))

X1 = c( rnorm (4, 10, 4), rnorm (4, 12, 6), rnorm (4, 10, 7),rnorm (4, 5, 2),
rnorm (4, 8, 4), rnorm (4,7, 2))

X2 = X1 + rnorm(length(X1), 0,3)

yvar <- c(X1, X2)

X <- c(rep( 1, length(X1)), rep( 2, length(X2))) # dummy x variable

dataf <- data.frame(as.factor(block), as.factor(gen), as.factor(X), yvar )



My objective to estimate variance-covariance between two variables X1 and
X2. Means that I need to fit something like unstructure (UN) covariance
structure.



Question 1: I got the following error

require("lme4");

fm1Gen <- lmer(yvar ~ X + gen +(1|block), data= dataf) # Question 1: should
I consider X fixed or random



Error in model.frame.default(data = dataf, formula = yvar ~ X + gen +  :
  variable lengths differ (found for 'gen')



A tried nlme too.

require(nlme)

fm2Gen <- lme(yvar ~ X + gen,  random= ~ 1|block, data= dataf)

Error in model.frame.default(formula = ~yvar + X + gen + block, data = list(
:
  variable lengths differ (found for 'gen') # similar error



Question 2: How can get I covariance matrix between X1 and X2 either using
lme4 or lmer.

               X1        X2

X1           Var (X1) Cov(X1,X2)

X2           Cov(X1, X2)  Var(X2)



Should I put gen in the model to do this? Should I specify something in "*
correlation* =  "

Thank you for your time

Maya

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to