---
title: "Group_analysis"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Group_analysis}
  %\VignetteEngine{knitr::rmarkdown_notangle}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
is_check <- ("CheckExEnv" %in% search()) || any(c("_R_CHECK_TIMINGS_",
             "_R_CHECK_LICENSE_") %in% names(Sys.getenv()))

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = "center",
  eval = !is_check, purl = !is_check
)
```



```{r setup}
library(BayesDLMfMRI)
library(oro.nifti)
library(neurobase)
```


Now we illustrate how to run an fMRI group analysis as described in Cardona-Jiménez and Pereira [2021]. In this first version of the BayesDLMfMRI package, we implement functions to detect brain activation for single groups. The comparison analysis between groups is under development and will be offered in future versions of the package. First, we read the fMRI images of 2 subjects taken from the "voice-localizer" example:

```{r}
DataGroups <- get_example_fMRI_data_group()
```

The complete dateset(21 subjets) and results are avalible in Cardona-Jiménez and Pereira [2021].



```{r}
# load example covaraites and mask
data("covariates", package="BayesDLMfMRI")
data("mask", package="BayesDLMfMRI")
```


In order to run any of the functions available in this package to perform fMRI group analysis, the data sets or sets of images from each subject must be stored on a list object as it is shown above. To deal with this massive amount of information, the user must have a big RAM capacity available on the machine where this process will be run. It is also recommended to have a multi-core processor available in order to speed up computation time. The arguments or input parameters for any functions offered in this package to run group analysis are almost identical to those required for individual analysis. There is only an additional argument needed  (mask), which adds a 3D array that works as a brain of reference (MNI atlas) for the group analysis.

```{r}
res <- ffdGroupEvidenceFFBS(ffdGroup = DataGroups, covariates = Covariates, 
                            m0=0, Cova=100, delta = 0.95, S0 = 1, n0 = 1, N1 = FALSE, Nsimu1 = 100, 
                            Cutpos = 30, r1 = 1, mask = mask, Ncores = 1)
```



```{r}
str(res)
```

