Skip to content

Commit b46e383

Browse files
author
Petersen
committed
20240109 - fix to address frequency counts of zero
1 parent 9a95b22 commit b46e383

5 files changed

Lines changed: 32 additions & 24 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: petersenlab
22
Type: Package
33
Title: Package of R Functions for the Petersen Lab
4-
Version: 0.1.2-9027
4+
Version: 0.1.2-9028
55
Authors@R: person("Isaac T.", "Petersen",
66
email = "isaac-t-petersen@uiowa.edu",
77
role = c("aut", "cre"),

R/recodeIntensity.R

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
#' zero (i.e., if the behavior has not occurred).
1010
#'
1111
#' @param intensity The intensity of the behavior.
12-
#' @param not_in_the_past_year Whether or not the behavior did NOT occur in
13-
#' the past year. If \code{yes}, the behavior did not occur in the past year.
12+
#' @param did_not_occur Whether or not the behavior did NOT occur. If
13+
#' \code{yes}, the behavior did not occur (in the given timeframe).
1414
#' @param frequency The frequency of the behavior.
1515
#' @param item_names The names of the questionnaire items.
1616
#' @param data The data object.
1717
#' @param frequency_vars The name(s) of the variables corresponding to the
1818
#' number of occurrences (\code{num_occurrences}).
19-
#' @param not_in_past_year_vars The name(s) of the variables corresponding to
20-
#' whether the behavior did not occur in the past year
21-
#' (\code{not_occurred_past_year}).
19+
#' @param did_not_occur_vars The name(s) of the variables corresponding to
20+
#' whether the behavior did not occur in the past year (\code{did_not_occur}).
2221
#'
2322
#' @return
2423
#' The intensity of the behavior.
@@ -27,31 +26,41 @@
2726

2827
#' @rdname recodeBehaviorIntensity
2928
#' @export
30-
recode_intensity <- function(intensity, not_in_the_past_year = NULL, frequency = NULL){
29+
recode_intensity <- function(intensity, did_not_occur = NULL, frequency = NULL){
3130
if(missing(frequency) | is.null(frequency)){
32-
result <- ifelse(is.na(not_in_the_past_year), intensity, ifelse(not_in_the_past_year == 1, 0, intensity))
33-
} else if(missing(not_in_the_past_year) | is.null(not_in_the_past_year)){
31+
result <- ifelse(is.na(did_not_occur), intensity, ifelse(did_not_occur == 1, 0, intensity))
32+
} else if(missing(did_not_occur) | is.null(did_not_occur)){
3433
result <- ifelse(is.na(frequency), intensity, ifelse(frequency == 0, 0, intensity))
35-
}
34+
} else(
35+
result <- ifelse(did_not_occur == 1, 0, ifelse(frequency == 0, 0, intensity))
36+
)
3637

3738
return(result)
3839
}
3940

4041
#' @rdname recodeBehaviorIntensity
4142
#' @export
42-
mark_intensity_as_zero <- function(item_names, data, not_in_past_year_vars = NULL, frequency_vars = NULL) {
43+
mark_intensity_as_zero <- function(item_names, data, did_not_occur_vars = NULL, frequency_vars = NULL) {
4344
if(missing(frequency_vars) | is.null(frequency_vars)){
4445

4546
recoded <- Map(
4647
recode_intensity,
4748
intensity = data[, item_names],
48-
not_in_the_past_year = data[, not_in_past_year_vars])
49+
did_not_occur = data[, did_not_occur_vars])
50+
51+
} else if(missing(did_not_occur_vars) | is.null(did_not_occur_vars)){
52+
53+
recoded <- Map(
54+
recode_intensity,
55+
intensity = data[, item_names],
56+
frequency = data[, frequency_vars])
4957

50-
} else if(missing(not_in_past_year_vars) | is.null(not_in_past_year_vars)){
58+
} else {
5159

5260
recoded <- Map(
5361
recode_intensity,
5462
intensity = data[, item_names],
63+
did_not_occur = data[, did_not_occur_vars],
5564
frequency = data[, frequency_vars])
5665

5766
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ remotes::install_github("DevPsyLab/petersenlab")
1414

1515
To obtain the citation for the `petersenlab` package, run `citation("petersenlab")`; the citation is:
1616

17-
Petersen, I. T. (2023). *petersenlab: Package of R functions for the Petersen Lab*. R package version 0.1.2-9027. https://github.com/DevPsyLab/petersenlab, https://doi.org/10.5281/zenodo.7602890
17+
Petersen, I. T. (2023). *petersenlab: Package of R functions for the Petersen Lab*. R package version 0.1.2-9028. https://github.com/DevPsyLab/petersenlab, https://doi.org/10.5281/zenodo.7602890
1818

1919
A `BibTeX` entry for `LaTeX` users is:
2020
```
@@ -23,7 +23,7 @@ A `BibTeX` entry for `LaTeX` users is:
2323
title = {{petersenlab}: Package of {R} functions for the {Petersen Lab}},
2424
url = {https://github.com/DevPsyLab/petersenlab},
2525
doi = {10.5281/zenodo.7602890},
26-
version = {0.1.2-9027},
26+
version = {0.1.2-9028},
2727
year = {2023}
2828
}
2929
```

man/recodeBehaviorIntensity.Rd

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renv.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@
112112
},
113113
"Rcpp": {
114114
"Package": "Rcpp",
115-
"Version": "1.0.11",
115+
"Version": "1.0.12",
116116
"Source": "Repository",
117117
"Repository": "CRAN",
118118
"Requirements": [
119119
"methods",
120120
"utils"
121121
],
122-
"Hash": "ae6cbbe1492f4de79c45fce06f967ce8"
122+
"Hash": "5ea2700d21e038ace58269ecdbeb9ec0"
123123
},
124124
"backports": {
125125
"Package": "backports",

0 commit comments

Comments
 (0)