Skip to content

Error in random effects-"Number of items to replace is not a multiple of replacement length" #72

@Jigyasa3

Description

@Jigyasa3

Hey!

I am following the supplementary material of [https://nph.onlinelibrary.wiley.com/doi/epdf/10.1111/nph.14397] on my own data. My data is slightly different, but the questions I am looking at are similar to the paper. But I keep running into an error, which I can't find any information about on the internet.

My aim is to see if the lineage of the species helps explain the gene relative abundance.
#my data-
#K00297 is the log transformed gene relative abundance data-
> wood_0.5_df_sub_pez2%>%dplyr::select(K00297,lineage,diet_type_number2)%>%head()
K00297 lineage diet_type_number2 tip_names
1 0.4009284 Termitinae 3 Termitinae_sp1
2 0.3649912 Termitinae 3 Termitinae_sp2
3 -0.1522581 Termitinae 3 Termitinae_sp3
4 0.1961155 Termitinae 2 Termitinae_sp4
5 0.5761659 Termitinae 2 Termitinae_sp5
6 0.2031437 Termitinae 3 Termitinae_sp6

#the R code-

>wood_0.5_df_sub_pez2$lineage = as.factor(wood_0.5_df_sub_pez2$lineage) 
>wood_0.5_df_sub_pez2$diet_type_number2 = as.factor(wood_0.5_df_sub_pez2$diet_type_number2) 
>nspp <- nlevels(wood_0.5_df_sub_pez2$lineage)
 >nsite <- nlevels(wood_0.5_df_sub_pez2$diet_type_number2)

#to standardize the phylo var-covar matrix

>Vphy <- vcv(phy)
>Vphy <- Vphy[order(phy$tip.label),order(phy$tip.label)]
>Vphy <- Vphy / max(Vphy)
>Vphy <- Vphy / det(Vphy) ^ (1 / nspp)

#specify random effects

re.site <- list(1, site = wood_0.5_df_sub_pez2$diet_type_number2, covar = diag(nsite))
re.sp <- list(1, sp = wood_0.5_df_sub_pez2$lineage, covar = diag(nspp))
re.sp.phy <- list(1, sp = wood_0.5_df_sub_pez2$lineage, covar = Vphy)

sp is nested within site

re.nested.phy <- list(1, sp = wood_0.5_df_sub_pez2$lineage, covar = Vphy, site = wood_0.5_df_sub_pez2$diet_type_number2)
 re.nested.rep <- list(1, sp = wood_0.5_df_sub_pez2$lineage, covar = solve(Vphy), site = wood_0.5_df_sub_pez2$diet_type_number2)

##run the full model without s2.init variable to get the random effect variance, and then add that to the final model.

this is the full model,without s2.init

z_test <- communityPGLMM(K00297 ~ 1, data = wood_0.5_df_sub_pez2, family = "gaussian", sp = wood_0.5_df_sub_pez2$lineage, site=wood_0.5_df_sub_pez2$diet_type_number2, random.effects = list(re.sp, re.sp.phy,re.site, re.nested.phy), REML = F, verbose = F)

#the error-
Error in Z.i[, counter] <- re.i[[1]] * as.numeric(i.levels == re.i[[2]]) :
number of items to replace is not a multiple of replacement length

#If I run the model with sp=wood_0.5_df_sub_pez2$tip.names (and make the corresponding changes to the random effects also), then the error is-
Error: Matrices must have same dimensions in .Arith.Csparse(e1, e2, .Generic, class. = "dgCMatrix")

Any suggestions?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions