Skip to content

Commit 7477e53

Browse files
authored
Merge pull request #3 from leibniz-psychology/development
Add first batch of scripts for fearbase analysis
2 parents c4aabd1 + 9ad5ca6 commit 7477e53

37 files changed

Lines changed: 1414 additions & 53 deletions

.Rbuildignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
^.*\.Rproj$
2-
^\.Rproj\.user$
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
csv_to_rds.R
4+
^[.]?air[.]toml$
5+
^\.vscode$
6+
.dockerignore
7+
.github
8+
data-preprocessing.R

.Rprofile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (interactive()) {
2+
suppressMessages(require(devtools))
3+
}

.github/workflows/manifests/development/adjustedBaseImage/Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG OCPU_PASS
44

55
#install needed dependenciesp
66
RUN apt-get update && apt-get install -y \
7-
libcurl4-gnutls-dev \
7+
libcurl4-gnutls-dev libcairo2-dev\
88
&& apt install -y cmake \
99
## clean up
1010
&& apt-get clean \
@@ -23,6 +23,18 @@ RUN R -e "install.packages('rlang')"
2323
RUN R -e 'remove.packages("rlang", "/usr/lib/opencpu/library")'
2424
RUN R -e 'remove.packages("vctrs", "/usr/lib/opencpu/library")'
2525
RUN R -e "install.packages('vctrs')"
26+
RUN R -e "install.packages('tidyverse')"
27+
RUN R -e "install.packages('patchwork')"
28+
RUN R -e "install.packages('lme4')"
29+
RUN R -e "install.packages('lmerTest')"
30+
RUN R -e "install.packages('psych')"
31+
RUN R -e "install.packages('gsheet')"
32+
RUN R -e "install.packages('plotly')"
33+
RUN R -e "install.packages('ggridges')"
34+
RUN R -e "install.packages('ggiraph')"
35+
RUN R -e "install.packages('shadowtext')"
36+
RUN R -e "install.packages('broom.mixed')"
37+
RUN R -e "install.packages('ggrepel')"
2638

2739

2840

.github/workflows/manifests/development/opencpu/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ RUN cd /home/opencpu && \
1010
apt-get update && \
1111
apt-get install -y openssl && \
1212
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
13-
-keyout fearbase_ssl.key -out fearbase_ssl.crt -subj "/CN=fearbase.dev.zpid.org" \
14-
-addext "subjectAltName=DNS:fearbase.dev.zpid.org,DNS:www.fearbase.dev.zpid.org,IP:127.0.0.1"
13+
-keyout fearbase-ocpu_ssl.key -out fearbase-ocpu_ssl.crt -subj "/CN=fearbase-ocpu.dev.zpid.org" \
14+
-addext "subjectAltName=DNS:fearbase-ocpu.dev.zpid.org,DNS:www.fearbase-ocpu.dev.zpid.org,IP:127.0.0.1"
1515

1616
RUN cd /home/opencpu && \
17-
mv /home/opencpu/fearbase_ssl.crt /etc/ssl/certs/ && \
18-
mv /home/opencpu/fearbase_ssl.key /etc/ssl/private/
17+
mv /home/opencpu/fearbase-ocpu_ssl.crt /etc/ssl/certs/ && \
18+
mv /home/opencpu/fearbase-ocpu_ssl.key /etc/ssl/private/
1919

2020
#copy some config files
2121
COPY . /home/opencpu/fearbase

.gitignore

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
11
.idea
22
/.idea/
3-
.Rproj.user
3+
.vscode
4+
.github
5+
backlog.md
6+
7+
# --- R Specific ---
48
.Rhistory
9+
*.RData
10+
.Ruserdata
11+
.Rproj.user/
12+
.Rapp.history
13+
.Rsession_device
14+
15+
# --- Package Build Artifacts ---
16+
# These are generated when you build or check your package
17+
*.Rcheck/
18+
/vignettes/*.html
19+
/vignettes/*.pdf
20+
/man/*.Rd
21+
# Note: Some people prefer to track .Rd files,
22+
# but they are auto-generated from Roxygen2 tags in your R/ files.
23+
24+
# --- Data & Results (The Pipeline specific stuff) ---
25+
# Ignore all raw data formats to be safe
26+
*.csv
27+
*.xlsx
28+
*.xls
29+
*.rds
30+
*.rda
31+
*.parquet
32+
*.sqlite
33+
*.db
34+
35+
# Ignore your output reports (rendered from your pipeline)
36+
/inst/reports/*.html
37+
/inst/reports/*.pdf
38+
/output/
39+
/paper/
40+
/results/
41+
*.tar.gz
42+
*.zip
43+
44+
# --- Environment & Secrets ---
45+
.env
46+
.Renviron
47+
auth/
48+
credentials/
49+
*-secret.R
50+
51+
# --- OS Specific ---
52+
.DS_Store
53+
Thumbs.db

DESCRIPTION

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
Package: fearbase
2-
Type: Package
3-
Title: FEARBASE
4-
Version: 0.0.1
5-
Maintainer: The package maintainer <xxx@leibniz-psychology.org>
6-
Description:
7-
License: GNU General Public License Version 2 + file LICENSE
8-
Encoding: UTF-8
9-
LazyData: true
10-
RoxygenNote: 7.1.1
11-
Imports:
12-
Depends:
1+
Package: fearbase
2+
Type: Package
3+
Title: fearbase
4+
Version: 0.0.1
5+
Maintainer: The package maintainer <xxx@leibniz-psychology.org>
6+
Description: A package of functions to analyze and visualize data from the fearbase database.
7+
Author: Fritz Becker
8+
License: GNU General Public License Version 2 + file LICENSE
9+
Encoding: UTF-8
10+
LazyData: true
11+
RoxygenNote: 7.3.3
12+
Imports:
13+
dplyr,
14+
ggplot2,
15+
tidyr,
16+
readr,
17+
purrr,
18+
tibble,
19+
patchwork,
20+
stringr,
21+
forcats,
22+
ggridges,
23+
ggrepel,
24+
psych,
25+
broom.mixed
26+
Depends:
27+
R (>= 4.1)
28+
Suggests:
29+
testthat (>= 3.0.0)
30+
Config/testthat/edition: 3

NAMESPACE

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
importFrom("stats", "as.formula", "pnorm", "predict", "qnorm")
4-
importFrom("utils", "str")
5-
6-
export(jsonSummary)
7-
export(checkData)
3+
export(createCsv)
4+
export(age)
5+
export(ageDescriptives)
6+
export(allStudies)
7+
export(dataCollectionYear)
8+
export(descriptives)
9+
export(instructions)
10+
export(measuresHeatmap)
11+
export(peakDetectionWindows)
12+
export(phasesHeatmap)
13+
export(reinforcementRates)
14+
export(sampleSizeByStudy)
15+
export(sex)
16+
export(stimModality)
17+
export(trialsPhaseParticipant)
18+
export(phaseResponseDistribution)
19+
export(dataDensityMatrix)
20+
export(studyDesign)
21+
import(dplyr)
22+
import(ggplot2)
23+
import(patchwork)
24+
importFrom(readr,read_csv)
25+
importFrom(tidyr,drop_na)
26+
importFrom(tidyr,pivot_longer)
27+
importFrom(tidyr,pivot_wider)

R/age.R

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#' Age distribution
2+
#'
3+
#' @param dl The data in long format
4+
#' @param type The type of plot to produce. Either "histogram", "hist", "h" or "ridge", "density", "r", "d".
5+
#' @param grouping_variable A string specifying the variable to group by (allowed values: "condition_id", "study_id", "paper_cond_id", or "paper_study_id").
6+
#'
7+
#' @return A ggplot object.
8+
#' @export
9+
age <- function(
10+
dl,
11+
type = "histogram",
12+
grouping_variable = "study_id"
13+
) {
14+
# Process Data
15+
data_age <- dl |>
16+
filter(measure == "age") |>
17+
select(study_id, participant_id, value, measure) |>
18+
mutate(
19+
age = as.numeric(value),
20+
across(study_id, as.factor)
21+
) |>
22+
filter(!is.na(age))
23+
24+
# Plot
25+
study_order <- data_age |>
26+
group_by(.data[[grouping_variable]]) |>
27+
summarise(mean_age = median(age)) |>
28+
arrange(desc(mean_age)) |>
29+
pull(.data[[grouping_variable]])
30+
31+
if (tolower(type) %in% c("histogram", "hist", "h")) {
32+
data_age <- data_age |>
33+
group_by(age, .data[[grouping_variable]]) |>
34+
summarise(n = n())
35+
36+
data_age[[grouping_variable]] <- factor(
37+
data_age[[grouping_variable]],
38+
levels = study_order
39+
)
40+
41+
graph <- data_age |>
42+
ggplot(aes(x = age, y = n)) +
43+
geom_bar(
44+
aes(fill = .data[[grouping_variable]]),
45+
stat = "identity",
46+
color = "white",
47+
linewidth = .2
48+
) +
49+
labs(x = "Age", y = "Number of Participants", fill = "Study ID")
50+
} else if (tolower(type) %in% c("ridge", "density", "r", "d")) {
51+
data_age[[grouping_variable]] <- factor(
52+
data_age[[grouping_variable]],
53+
levels = study_order
54+
)
55+
56+
graph <- data_age |>
57+
ggplot(aes(
58+
x = age,
59+
y = .data[[grouping_variable]],
60+
group = .data[[grouping_variable]],
61+
fill = .data[[grouping_variable]]
62+
)) +
63+
ggridges::geom_density_ridges() +
64+
labs(x = "Age", y = "Study ID", fill = "Study ID") +
65+
theme(legend.position = "none")
66+
} else {
67+
stop("unknown argument type")
68+
}
69+
return(graph)
70+
}
71+
72+
#' Age descriptives
73+
#'
74+
#' @param dl The data in long format.
75+
#'
76+
#' @return A data frame with mean, sd, min and max age.
77+
#' @export
78+
ageDescriptives <- function(dl, grouping_variable = "study_id") {
79+
age <- dl |>
80+
filter(measure == "age") |>
81+
select(.data[[grouping_variable]], participant_id, value, measure) |>
82+
mutate(
83+
age = as.numeric(value),
84+
!!grouping_variable := as.factor(.data[[grouping_variable]])
85+
) |>
86+
filter(!is.na(age)) |>
87+
summarise(
88+
mean_age = mean(age),
89+
sd = sd(age),
90+
min = min(age),
91+
max = max(age)
92+
)
93+
94+
return(age)
95+
}

R/checkData.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
#' A \code{string} representing the dataset name that should be used.
66

77
checkData <- function(d) {
8-
98
dat <- tryCatch(
10-
{get(d)},
11-
error=function(cond) {
9+
{
10+
get(d)
11+
},
12+
error = function(cond) {
1213
message(paste("This dataset does not exist:", d))
1314
message("Here's the original error message:")
1415
message(cond)
1516
stop("stopped code because of error")
1617
},
17-
warning=function(cond) {
18+
warning = function(cond) {
1819
message(paste("input caused a warning:", d))
1920
message("Here's the original warning message:")
2021
message(cond)

0 commit comments

Comments
 (0)