Giter VIP home page Giter VIP logo

multilevelcoda's Introduction

multilevelcoda

R-CMD-check CRAN Version lifecycle

Overview

This package provides functions to model compositional data in a multilevel framework using full Bayesian inference. It integrates the principes of Compositional Data Analysis (CoDA) and Multilevel Modelling and supports both compositional data as an outcome and predictors in a wide range of generalized (non-)linear multivariate multilevel models.

Installation

To install the latest release version from CRAN, run

install.packages("multilevelcoda")

The current developmental version can be downloaded from github via

if (!requireNamespace("remotes")) {
  install.packages("remotes")
}
remotes::install_github("florale/multilevelcoda")

Because multilevelcoda is built on brms, which is based on Stan, a C++ compiler is required. The program Rtools (available on https://cran.r-project.org/bin/windows/Rtools/) comes with a C++ compiler for Windows. On Mac, Xcode is required. For further instructions on how to get the compilers running, see the prerequisites section on https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started.

Resources

You can learn about the package from these vignettes:

Citing multilevelcoda and related software

TBA

multilevelcoda's People

Contributors

florale avatar jwiley avatar paul-buerkner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

multilevelcoda's Issues

substitution() format

Hello there!

While working with the multilevelCoDA package, I tried to understand how to use the substitution() function.

First of all, the example [https://florale.github.io/multilevelcoda/reference/substitution.html] do work. However, I'm getting error messages when trying to apply it to other formats.

For instance, if mv_test =

mv_test <- brmcoda(compilr = cilr_test,
              formula =   Stress ~ ilr1 + ilr2 + ilr3 + ilr4  + (1 | ID),
              cores = 8, seed = 123, backend = "cmdstanr")

then

substitution(object = mv_test,delta = 5)

I get the following error:

Error: The following variables can neither be found in 'data' nor in 'data2': 'ilr1', 'ilr2', 'ilr3', 'ilr4'

However, when I look at my data.frame, I do see it.

    Stress     ilr1  ilr2    ilr3    ilr4  ID
1        4  0.29104 1.202  0.6298  1.7095 185
2        7 -0.47590 1.580 -0.8348  0.9857 185
3        3 -0.49829 1.335  1.3223  2.6373 185
4        2 -0.31260 1.367 -0.0314  0.5533 185
5        8  0.20438 1.431 -0.6875  0.7313 185
6        8 -0.44414 1.156 -0.0955  0.6683 185```

Then, I get different errors when I try to apply the substitution with compositional data as outcome. 

```mv_test2 <- brmcoda(compilr = cilr_test,
              formula = mvbind(ilr1, ilr2, ilr3, ilr4) ~ 1 + (1 | ID),
              cores = 8, seed = 123, backend = "cmdstanr")

 substitution(object = mv_test2,delta = 5)
Error in y0[, h] : incorrect number of dimensions

And when I use my own data:
[Where FB is a 3 level within subjects condition.

mv <- brmcoda(compilr = cilr,
              formula = mvbind(ilr1, ilr2, ilr3) ~ FB + (1 | Participant),
              cores = 8, seed = 123, backend = "cmdstanr")

substitution(object = mv,delta = 5)
Error in `[.data.frame`(comp0, , head(.SD, 1), by = eval(object$CompILR$idvar)) : 
  unused argument (by = eval(object$CompILR$idvar))

Any ideas on how I should se tup the data so that it works?

Thanks!

bug

I found another bug:
plotsub(data=subm1$BetweenSub$TST,

  •     x='sleep',y='stress')
    

Error in plotsub(data = subm1$BetweenSub$TST, x = "sleep", y = "stress") :
没有"plotsub"这个函数
your valuable suggestion is necessary.

classification of response

Excuse me, sir, I have a question.
In the function 'brmcoda', the response in the formula is numeric, such as 'formula = Stress ~ '.
If the response in my data is a categorical outcome, how to include it in the formula?
Looking forward to your reply!

Please make a minor release, since 1.2.3 is broken with the current `brms`

@florale Released 1.2.3 fails to build:

--->  Building R-multilevelcoda
xinstall: mkdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_R_R-multilevelcoda/R-multilevelcoda/work/build
Executing:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_R_R-multilevelcoda/R-multilevelcoda/work/multilevelcoda" && /opt/local/bin/R CMD INSTALL . --library=/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_R_R-multilevelcoda/R-multilevelcoda/work/build --install-tests 
* installing *source* package ‘multilevelcoda’ ...
** package ‘multilevelcoda’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** byte-compile and prepare package for lazy loading
Error: object ‘launch_shinystan’ is not exported by 'namespace:brms'
Execution halted
ERROR: lazy loading failed for package ‘multilevelcoda’

However, 6669071 work fine. The problem is it is still 1.2.3.
Please make a minor release incorporating the fix.

bug

This is my code:
pkgbuild::find_rtools()
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
install_cmdstan(dir = 'D:/R-4.0.5')
set_cmdstan_path('D:/R-4.0.5/cmdstan-2.32.2')
cmdstan_path()
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
library(cmdstanr)
library(multilevelcoda)
library(brms)
library(doFuture)
library(bayestestR)
options(digits = 3) # reduce number of digits shown
data("mcompd")
data("sbp")
data("psub")
cilr <- compilr(data = mcompd, sbp = sbp,
parts = c("TST", "WAKE", "MVPA", "LPA", "SB"), idvar = "ID", total = 1440)
m <- brmcoda(compilr = cilr,
formula = Stress ~ bilr1 + bilr2 + bilr3 + bilr4 +
wilr1 + wilr2 + wilr3 + wilr4 + (1 | ID),
cores = 8, seed = 123, backend = "cmdstanr")
I have the following error:

m <- brmcoda(compilr = cilr,

  •          formula = Stress ~ bilr1 + bilr2 + bilr3 + bilr4 +
    
  •            wilr1 + wilr2 + wilr3 + wilr4 + (1 | ID),
    
  •          cores = 8, seed = 123, backend = "cmdstanr")
    

Compiling Stan program...
Error in rethrow_call(c_processx_exec, command, c(command, args), pty, :
Command 'make' not found @win/processx.c:982 (processx_exec)
Type .Last.error.trace to see where the error occurred
And I want to know how to deal with this error, please give me some suggestion, thanks

Issue with Substitution

Hello,

I keep getting the following error

Error in [.data.frame(d0, , colnames(d0) %in% colnames(object$CompILR$data), :
unused argument (with = FALSE)

Code:
subm2 <- substitution(object = model1, delta = 1:2 ref = "clustermean", level ="within", weight = 'proportional')

I get it to work with 'grandmean', but only if I add weight = 'proportional' (which I was planning to do anyway) - but this does not fix it for clustermean. Changing the delta, level, or weight doesn't fix it.

Removing weights gives (for both grandmean/clustermean setting)
Error in [.data.frame(d0, , head(.SD, 1), by = eval(object$CompILR$idvar)) :
unused argument (by = eval(object$CompILR$idvar))

Model 1's output looks fine and output of the substitution model for the grandmean as well.

bayes_factor Fatal error

Hello there!

Trying to adapt the multilevelCoDA to my data.

When doing the examples, I found a "bug" with the [bayes_factor](mv$Model, mv0$Model) function.
It returned a fatal error and R needed to be restarted.

Any idea what could cause that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.