-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.Rmd
133 lines (87 loc) · 4.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# NeuroDecodeR: Neural Decoding in R
<!-- badges: start -->
[](https://github.com/emeyers/NeuroDecodeR/actions/workflows/R-CMD-check.yaml)
[](https://ci.appveyor.com/project/emeyers/NeuroDecodeR)
[](https://coveralls.io/github/emeyers/NeuroDecodeR)
<!-- badges: end -->
<p>
## Overview
*Neural decoding* is a data analysis method that uses pattern classifiers to
predict experimental conditions based on neural activity. The NeuroDecodeR
package makes it easy to do neural decoding analyses in R.
## Installation
You can install NeuroDecodeR package from github using:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("emeyers/NeuroDecodeR")
```
## Documentation
The documentation for this package is available at: https://emeyers.github.io/NeuroDecodeR/
To get started we recommend you read the [introductory tutorial](https://emeyers.github.io/NeuroDecodeR/articles/introduction_tutorial.html)
## Usage
The package is based on 5 abstract object types:
1. `Datasources (DS)`: generate training and test sets.
2. `Feature preprocessors (FP)`: apply preprocessing to the training and test sets.
3. `Classifiers (CL)`: learn relationships on the training set and make
predictions on the test data.
4. `Result Metrics (RM)`: summarize the prediction accuracies.
5. `Cross-validators (CV)`: take the DS, FP and CL objects and run a
cross-validation decoding procedure.
By combing different versions of these 5 object types together, it is possible
to run a range of different decoding analyses.
Below is a brief illustration of how to use the NDR to do a simple decoding
analysis. To learn how to use the NDR please see the [documentation
website](https://emeyers.github.io/NeuroDecodeR/) and the package vignettes.
```{r basic_ndr_analysis}
library(NeuroDecodeR)
# file to data in "binned format"
basedir_file_name <- system.file(file.path("extdata", "ZD_150bins_50sampled.Rda"),
package="NeuroDecodeR")
# create the DS, FP, CL, RM, and CV objects
ds <- ds_basic(basedir_file_name, 'stimulus_ID', 5, num_label_repeats_per_cv_split = 3)
fps <- list(fp_zscore())
cl <- cl_max_correlation()
rms <- list(rm_main_results(), rm_confusion_matrix())
cv <- cv_standard(datasource = ds,
classifier = cl,
feature_preprocessors = fps,
result_metrics = rms,
num_resample_runs = 2) # better to use more resample runs for actual analyses (default is 50)
# run a decoding analysis (this takes a few minutes)
DECODING_RESULTS <- run_decoding(cv)
```
```{r line_plot, fig.height = 3, fig.width = 8, fig.align = "center"}
# plot the results for three different result types
plot(DECODING_RESULTS$rm_main_results, results_to_show = 'all', type = 'line')
```
```{r TCD_plot, fig.height = 3.5, fig.width = 5, fig.align = "center"}
# create a temporal cross decoding plot
plot(DECODING_RESULTS$rm_main_results)
```
## Running an analysis using pipes (|>)
One can also run a decoding analysis using the pipe (|>) operator to string together the different NDR objects as shown below.
```{r pipe_example, fig.height = 3, fig.width = 7, fig.align = "center"}
basedir_file_name <- system.file(file.path("extdata", "ZD_500bins_500sampled.Rda"), package="NeuroDecodeR")
DECODING_RESULTS <- basedir_file_name |>
ds_basic('stimulus_ID', 6, num_label_repeats_per_cv_split = 3) |>
cl_max_correlation() |>
fp_zscore() |>
rm_main_results() |>
rm_confusion_matrix() |>
cv_standard(num_resample_runs = 2) |>
run_decoding()
plot(DECODING_RESULTS$rm_confusion_matrix)
```