Skip to content

TaxMeta: problem with fixed variable #1

Description

@yvanrichard

There's a mismatch between betas, variable names, and covariates when there's a fixed effect.

When there is a fixed effect, the function constructs a model matrix, taking the first level of dataset[, fixed_fx] as the intercept. So the first level needs to be removed when renaming the MCMC samples, otherwise it throws an error.

Also, the way the model matrix is constructed, it can only deal with a single fixed variable:

 covs <- model.matrix(~factor(dataset[, fixed_fx]))

So the apply(data.frame(dataset[, fixed_fx], 2, function(x) sort(unique(x))) when renaming the MCMC samples can be simplified.

So I'd say that part

 colnames(cres)[grepl("betas", colnames(cres))] <-
      c("Intercept", unlist(apply(data.frame(dataset[, fixed_fx]), 2, function(x) sort(unique(x)))), cont_cov)

should be replaced with

 colnames(cres)[grepl("betas", colnames(cres))] <-
      c("Intercept", sort(unique(dataset[, fixed_fx]))[-1], cont_cov)

I'll try to submit a pull request

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