https://github.com/statismike/stenr
R6-based Standardization of Raw Discrete Scores
https://github.com/statismike/stenr
Last synced: 11 months ago
JSON representation
R6-based Standardization of Raw Discrete Scores
- Host: GitHub
- URL: https://github.com/statismike/stenr
- Owner: StatisMike
- License: other
- Created: 2021-11-01T21:08:53.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-31T17:58:17.000Z (almost 4 years ago)
- Last Synced: 2025-07-17T17:21:21.275Z (11 months ago)
- Language: R
- Homepage: https://statismike.github.io/stenR/
- Size: 5.42 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.width = 6,
fig.height = 4
)
Sys.setenv(LANGUAGE='en')
library(stenR)
```
# stenR 
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://app.codecov.io/gh/StatisMike/stenR)
`stenR` is a package tailored mainly for users and creators of psychological questionnaires,
though other social science researchers and survey authors can benefit greatly
from it.
It provides tools to help with processes necessary for conducting such studies:
1. processing data from raw item scores to raw factor/scale scores
1. standardization of the raw scores into standard scale of your choosing, either
by:
- normalization of the raw scores using frequency table (if no norms have
been developed before). Usually for authors of questionnaires or their
adaptations.
- importing scoring table developed by questionnaire authors - for researchers
only using the measure
Furthermore, tools for developing or using norms on grouped basis are also
provided (up to two intertwined grouping conditions are supported).
Most in-depth information is provided within vignette **Tour from data to results**
(for basic and verbose explanation) and less verbose but more complete in
**stenR usage** vignette.
## Installation
You can install the current version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("StatisMike/stenR")
```
## Usage
### Data processing
Process data from item raw scores to factor/scales scores
```{r data_process}
# Exemplary data provided within package
str(SLCS)
# create scale specifications
SL_spec <- ScaleSpec(
name = "Self-Liking",
item_names = c("SLCS_1", "SLCS_3", "SLCS_5", "SLCS_6", "SLCS_7",
"SLCS_9", "SLCS_11", "SLCS_15"),
min = 1,
max = 5,
reverse = c("SLCS_1", "SLCS_6", "SLCS_7", "SLCS_15")
)
SC_spec <- ScaleSpec(
name = "Self-Competence",
item_names = c("SLCS_2", "SLCS_4", "SLCS_8", "SLCS_10", "SLCS_12",
"SLCS_13", "SLCS_14", "SLCS_16"),
min = 1,
max = 5,
reverse = c("SLCS_8", "SLCS_10", "SLCS_13")
)
GS_spec <- CombScaleSpec(
name = "General Score",
SL_spec,
SC_spec
)
# summarize data into factors/scales
summed_data <- sum_items_to_scale(
data = SLCS,
SL_spec,
SC_spec,
GS_spec,
retain = c("user_id", "sex")
)
str(summed_data)
```
### Create *FrequencyTable*, *ScoreTable* for normalization
Generate norms from raw data to normalize and standardize results
```{r ungrouped_FT}
GS_ft <- FrequencyTable(summed_data$`General Score`)
plot(GS_ft)
GS_st <- ScoreTable(GS_ft, scale = STEN)
plot(GS_st)
normalized_GS <- normalize_score(
summed_data$`General Score`,
table = GS_st,
what = "sten"
)
normalized_data <- normalize_scores_df(
data = summed_data,
vars = "General Score",
GS_st,
what = "sten",
retain = c("user_id", "sex")
)
str(normalized_GS)
str(normalized_data)
```
### Create *GroupedFrequencyTable* and *GroupedScoreTable*
Generate norms for different groups on basis of up to two *GroupConditions*
objects
```{r grouped_tables}
sex_grouping <- GroupConditions(
conditions_category = "Sex",
"M" ~ sex == "M",
"F" ~ sex == "F",
"O" ~ sex == "O"
)
GS_gft <- GroupedFrequencyTable(
data = summed_data,
conditions = sex_grouping,
var = "General Score",
.all = FALSE
)
plot(GS_gft)
GS_gst <- GroupedScoreTable(GS_gft, scale = STEN)
plot(GS_gst)
grouping_normalized <- normalize_scores_grouped(
data = summed_data,
vars = "General Score",
GS_gst,
retain = c("user_id", "sex"),
what = "sten",
group_col = "Group"
)
str(grouping_normalized)
```
### Create and export *ScoringTable*
Export generated norms in universal format
```{r scoring_table}
ST_csv <- tempfile(fileext = ".csv")
GS_scoring <- to_ScoringTable(
table = GS_gst,
min_raw = 16,
max_raw = 80
)
export_ScoringTable(
table = GS_scoring,
out_file = ST_csv,
method = "csv"
)
```
### Create *ScoringTable* from **csv** or **json** file
Import *ScoringTable* from universally readable formats (eg. create **csv**
on basis of published norms)
```csv
"sten","M","F","O"
1,NA,"16-22",NA
2,"16-32","23-26",NA
3,"33-36","27-29","16-35"
4,"37-40","30-37",NA
5,"41-47","38-41","36-63"
6,"48-51","42-47","64-68"
7,"52-58","48-49",NA
8,"59-71","50-55","69-80"
9,"72-80","56-59",NA
10,NA,"60-80",NA
```
```{r import_scoring_table}
imported <- import_ScoringTable(
source = ST_csv,
method = "csv",
conditions = sex_grouping
)
scoring_normalized <- normalize_scores_scoring(
data = summed_data,
vars = "General Score",
imported,
retain = c("user_id", "sex"),
group_col = "Group"
)
str(scoring_normalized)
```