qsxsqsxs
qsxsqsxs

Reputation: 211

R with asreml package: Setting a keyword for multivariate model, however it just stays keyword is an "object not found"

I am using a dataset from an online practice tutorial and the code can be found at the bottom of Page 7 (https://tomhouslay.files.wordpress.com/2017/02/indivvar_mv_tutorial_asreml.pdf)

In the tutorial, they state that they are introducing "trait" as a keyword to signify a multivariate model, but when I run the exact same code I get the following:

Error in eval(parse(text = x), envir = data, enclos = asreml4Env) : object 'trait' not found.

The haggis practice csv file can be downloaded from here: https://figshare.com/articles/Haggis_data_behavioural_syndromes/4702540

Here is the code provided by the tutorial, has something changed with the asreml function?

asr_E_B_us <- asreml(cbind(scale(exploration),
                           scale(boldness)) ~ trait + 
                       trait:scale(assay_rep, scale = FALSE) + 
                       trait:scale(body_size), 
                     random =~ ID:us(trait, init = c(1, 
                                                     0.1,1)), 
                     residual =~ units:us(trait, init = c(0.1, 
                                                      0.1,0.1)), 
                     data = HData, 
                     maxiter = 100)

Upvotes: 2

Views: 134

Answers (1)

Kevin Wright
Kevin Wright

Reputation: 2697

The asreml function becomes confused when you try to use scale inside the function. Do the scaling first (and also you meed to make ID into a factor). Then call asreml.

HData <- read.csv("syndrome.csv")
head(HData)
   ID assay_rep boldness exploration fitness body_size
1 S_1         1    18.57       39.74      39     21.72
2 S_1         2    18.32       39.41      NA     21.55
3 S_1         3    20.33       40.16      NA     21.34
4 S_1         4    19.40       40.29      NA     20.78
5 S_2         1    20.70       39.47      56     25.71
6 S_2         2    18.60       40.12      NA     26.43

HData <- transform(HData, exploration=scale(exploration), boldness=scale(boldness),
                   ID = factor(ID))
asr_E_B_us <- asreml(cbind(exploration, boldness) ~ trait + 
                       trait:scale(assay_rep, scale = FALSE) + 
                       trait:scale(body_size), 
                     random =~ ID:us(trait, init = c(1, 0.1,1)), 
                     residual =~ units:us(trait, init = c(0.1, 0.1,0.1)), 
                     data = HData, 
                     maxiter = 100)

Upvotes: 1

Related Questions