Hi,
I'm using the mvMORPH package to fit a model with a phylogenetic generalized least squares. The package authors give code to simulate data but I'm having trouble making my data match the simulation data structure. Note that a phylogenetic tree is also required here but I'm omitting to make this post less messy.
#Making the simulation mvMORPH data
set.seed(1)
n <- 32 # number of species
p <- 50 # number of traits (p>n)
tree <- pbtree(n=n, scale=1) # phylogenetic tree
R <- crossprod(matrix(runif(p*p), ncol=p)) # a random symmetric matrix (covariance)
# simulate a BM dataset
Y <- mvSIM(tree, model="BM1", nsim=1, param=list(sigma=R, theta=rep(0,p)))
data=list(Y=Y)
#Example of my data
df1 <- data.frame(
var1 = c(1,16,0,0,0),
var2 = c(17,24,0,0,0),
var3 = c(2,1,0,39,3),
var4 = c(0,0,36,0,5),
var5 = c(3,2,0,0,16))
#Fits the desired model
data=list(df1=df1)
fit1 <- mvgls(df1~1, data=data, tre, model="BM", penalty="RidgeArch")
When I attempt to run the code to fit the model I get the error message "Error in svd(B, nu = 0) : infinite or missing values in 'x'".
A quick google suggested that this is because my data should not be a data frame, but rather a matrix. The issue is that after transforming my data to a matrix I get different outputs when using str() to see if the simulation data and my data match.
#Simulation data
num [1:32, 1:50] 2.93 3.2 5.77 2.65 2.5 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:32] "t17" "t18" "t5" "t11" ...
..$ : NULL
#My data
num [1:5, 1:5] 1 16 0 0 0 17 24 0 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "var1" "var2" "var3" "var4" ...
I'm assuming that my code won't run because the NULL and character lines should be switched, but not really sure how to do this.
Any suggestions? Thanks for the help!