1

I first upload the table. The table contains 9 rows, 6 of them are factors and the 3 left are discrete measures of growth rate of 152 individuals (n01,n02,n03). Then I specify the factors:

`r$feed <- factor (r$feed)`
`r$ph <- factor (r$ph)`
`r$aq <- factor (r$aq)`
`r$ind <- factor (r$ind)`
`r$wc <- factor (r$wc)`
`r$p0<- factor (r$p0)`

Following, I perform I melt the dataframe into a new table "r2" with the factors I am interested in and remove NA values with na.omit function.

`r2 <- data.table::melt(r,id.vars=c("feed","ph","aq","wc"),
                       measure=c("n01","n12","n23"),
                       variable.name="time",value.name="G")`

`r2<-na.omit(r2)`

r2 looks like this:

data.frame(
           G = c(0.184, 0.087, 1.747, 0.11, 0.39, 0.062, 0.08, 0.189, 0.068,
                 0.262, 0.048, 0.029, 0, 0.229, 0.175),
        feed = as.factor(c("HF", "HF", "HF", "HF", "HF", "HF", "HF", "HF",
                           "HF", "HF", "HF", "HF", "HF", "HF", "HF")),
          ph = as.factor(c("8.1", "8.1", "8.1", "8.1", "8.1", "8.1", "8.1",
                           "8.1", "8.1", "8.1", "8.1", "8.1", "8.1", "8.1",
                           "8.1")),
          aq = as.factor(c("1", "1", "1", "1", "1", "1", "2", "2", "2", "2",
                           "2", "2", "2", "3", "3")),
          wc = as.factor(c("3", "3", "2", "3", "2", "4", "3", "4", "2", "2",
                           "3", "3", "1", "4", "3")),
        time = as.factor(c("n01", "n01", "n01", "n01", "n01", "n01", "n01",
                           "n01", "n01", "n01", "n01", "n01", "n01", "n01",
                           "n01"))
)

After that, I set the fixed variance and apply and perfom 2 gls models, like this:

`vfix3 <- varIdent(form=~1|time*factor(aq))
    mix1 <- gls(G ~ ph+feed, weights=vfix3,data=r2)
    mix3 <- gls(G ~ ph+feed+wc+time, weights=vfix3,data=r2)`

The models seem to work fine since I can get the summary and anova of them. Then, I try to run post-hoc pairwise comparisons with lsmeans function from the package emmeans as it follows:

    print(lsmeans(mix1, list(pairwise~ph|feed), adjust="tukey"))

lsmeans seems to work fine with 2-factor model mix1. However, when executing lsmeans on model mix3 this error pops up:

Error in crossprod(x, y) : requires numeric/complex matrix/vector arguments

I have tried to transform the model to a matrix, but for the lsmeans function it is not a correct object. I have also tried not setting the factors and leaving the columns as numeric, but same error pops up. When reading about lsmeans function there I can't find any crossprod function related to it.


  • You should use SO [edit] facilities to post a sample dataset that produces this error. Otherwise it will be closed as irreproducible. – IRTFM Mar 20 '19 at 22:49
  • I agree. I’d like to look at this to see if there’s a bug I need to fix, but I need a reproducible example. Alternative place to provide example is on my github site — see ‘bug reports’ in the Description page for lsmeans or emmeans package. – Russ Lenth Mar 21 '19 at 18:02
  • Thank you very much, I have just edited the question with the dataset and the scripts. – Ariadna Martínez Apr 01 '19 at 08:54

0 Answers0