| Type: | Package |
| Title: | Calculate Results from WHO Model Disability Survey Data |
| Version: | 1.2.0 |
| Description: | The Model Disability Survey (MDS) https://www.who.int/activities/collection-of-data-on-disability is a World Health Organization (WHO) general population survey instrument to assess the distribution of disability within a country or region, grounded in the International Classification of Functioning, Disability and Health https://www.who.int/standards/classifications/international-classification-of-functioning-disability-and-health. This package provides fit-for-purpose functions for calculating and presenting the results from this survey, as used by the WHO. The package primarily provides functions for implementing Rasch Analysis (see Andrich (2011) <doi:10.1586/erp.11.59>) to calculate a metric scale for disability. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| Imports: | colorspace, dplyr, eRm (≥ 1.0-7), ggraph, ggplot2 (≥ 3.4.0), GPArotation, grDevices, igraph, nFactors, polycor, purrr, RColorBrewer, rlang, srvyr, TAM, tibble, tidygraph, tidyr, WrightMap |
| Depends: | R (≥ 3.6.0), psych |
| BugReports: | https://github.com/lindsayevanslee/whomds/issues |
| Suggests: | httr, knitr, lubridate, rmarkdown, testthat, withr |
| VignetteBuilder: | knitr |
| URL: | https://github.com/lindsayevanslee/whomds |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-12 02:45:55 UTC; lindsaylee |
| Author: | Lindsay Lee [aut, cre], Carolina Fellinghauer [ctb], World Health Organization [cph] |
| Maintainer: | Lindsay Lee <lindsayevanslee@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-12 10:40:02 UTC |
whomds: A package for calculating results from WHO Model Disability Survey
Description
The whomds package provides three categories of important functions: table functions, figure functions, and Rasch Analysis functions
Table functions
The table functions output different fit for purpose tables for reporting
results from the WHO Model Disability Survey (MDS). They begin with table_*()
Figure functions
The figures functions output different figures for reporting
results from the WHO Model Disability Survey (MDS). They begin with fig_*()
Rasch Analysis functions
These functions are used to complete an iteration of Rasch Analysis for WHO Model Disability Survey (MDS). They begin with rasch_*
Author(s)
Maintainer: Lindsay Lee lindsayevanslee@gmail.com
Authors:
Lindsay Lee lindsayevanslee@gmail.com
Other contributors:
Carolina Fellinghauer carolina.fellinghauer@data-fittery.ch [contributor]
World Health Organization disability@who.int [copyright holder]
References
WHO Model Disability Survey: https://www.who.int/health-topics/disability
See Also
Useful links:
Report bugs at https://github.com/lindsayevanslee/whomds/issues
Separation Reliability: Person Separation Reliability
Description
Copied from eRm::SepRel(), v1.0-1: This function calculates the proportion of person variance that is not due to error. The concept of person separation reliability is very similar to reliability indices such as Cronbach's alpha.
Usage
SepRel_1.0.1(pobject)
Arguments
pobject |
Object of class |
Details
See full documentation at https://www.rdocumentation.org/packages/eRm/versions/1.0-1/topics/Separation%20Reliability
Why whomds keeps its own copy. From version 1.0-2,
eRm::SepRel() excludes respondents who chose the lowest or the
highest option for every item. This copy of the earlier version includes
them, which gives a noticeably higher value in Model Disability Survey
data, where many respondents report no problems at all. whomds keeps the
earlier definition so that the PSI reported by rasch_model()
stays comparable with earlier WHO analyses. Keep this in mind when comparing
it with values from other software.
Value
SepRel returns a list object of class eRm_SepRel containing:
sep.rel |
the person separation reliability, |
SSD.PS |
the squared standard deviation (i.e., total person variability), |
MSE |
the mean square measurement error (i.e., model error variance). |
Author(s)
Original code by Adrian Brügger (Adrian.Bruegger@imu.unibe.ch), adapted by Marco J. Maier in package eRm v1.0-1
References
Wright, B.D., and Stone, M.H. (1999). Measurement essentials. Wide Range Inc., Wilmington. (https://www.rasch.org/measess/me-all.pdf 28Mb).
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# rasch_mds() also removes people with too many missing answers, here more
# than 2 of the 12 items. The model takes about 10 seconds on all 2500
# adults, so this example uses only the first 300 who remain
n_missing <- rowSums(is.na(df[items]))
df <- df[n_missing <= 2, ]
df <- df[1:300, ]
model <- rasch_model(df, items, vars_id = "HHID")
# the person separation reliability of the model; this is the same value
# that rasch_model() returns as PSI
SepRel_1.0.1(model$person_parameters)
model$PSI
Example of WHO Model Disability Survey data for adults
Description
An dummy data set of data from the WHO Model Disability Survey. All survey variables and demographic characteristics (except work status) are randomly generated. Responses to the survey questions and work status are from randomly selected rows of the 2014 Chilean implementation of the MDS, ENDIS II (2014).
Usage
df_adults
Format
A tibble with 2500 rows and 90 variables:
- HHID
household number
- strata
survey strata
- PSU
PSU id
- weight
survey weights
- sex
sex, Male or Female
- age
age in years
- age_cat
age catgory, one of "18-24", "25-39", "40-64", or "64-100"
- edu_cat
highest level of education attained
- work_cat
whether respondent is currently working, binary
- disability_score
metric scale of performance, from Rasch analysis
- disability_cat
performance level, as definted by WHO cutoffs of disability_score
Functioning section: On a scale from 1 (none) to 5 (extreme), in the last 30 days, taking into account any help or support you receive, how much has of a problem has it been for you to...
- F1
...stand up from sitting?
- F2
...stand for long periods of time, for example 30 minutes?
- F3
...leave the house?
- F4
...walk short distances, such as a street block or 100 meters?
- F5
...walk 10 blocks or a kilometer?
- F6
...do vigorous activities, such as play footbal, lift heavy objects, ride a bike or run?
- F7
...get where you want to go?
- F8
...manipulate small objects or opening a container?
- F9
...lift a 2L full bottle of water from your waist to eye level?
- F10
...wash or dress yourself?
- F11
...feed yourself?
- F12
...use the bathroom?
- F13
...cut your toenails?
- F14
...take care of your health, for example exercise, eat well or take your medications?
- F15
...see objects at a distance?
- F16
...see objects at arms length?
- F17
...hear a conversation in a quiet room?
- F18
...hear a conversation in a loud room?
- F19
...feel pain?
- F20
...sleep?
- F21
...feel tired or not have enough energy?
- F22
...feel short of breath?
- F23
...cough or wheeze?
- F24
...feel sad, down or depressed?
- F25
...feel worried, nervous or anxious?
- F26
...get along with people close to you, including your family and friends?
- F27
...get along with people you don't know?
- F28
...make new friends or maintain your friendships?
- F29
...have intimiate relationships?
- F30
...manage stress?
- F31
...cope with everything you have to do?
- F32
...be understood in your usual language?
- F33
...understand others in your usual language?
- F34
...forget things?
- F35
...remember the important things you have to do day-to-day?
- F36
...find solutions to your day-to-day problems?
- F37
...complete household tasks, like sweeping, cooking, arranging the house or taking our the trash?
- F38
...manage the money you have?
- F39
...do things for relaxation?
- F40
...participate in community activities?
- F41
...participate in local or national policitics or civil society?
- F42
...take care of others?
- F43
...get a job?
- F44
...obtain a higher education?
- F45
...use public transportation?
- F46
...get things done in your job (if not currently working, NA)?
- F47
...get things done at your school (if not currently studying, NA)?
Capacity section: On a scale from 1 (none) to 5 (extreme), in the last 30 days, withing taking into account any type of help or support, due to your health how much difficulty have you had with...
- C2
...seeing, without contact lenses or glasses?
- C3
...hearing, without hearing aids?
- C4
...walking or climbing steps?
- C5
...remembering or concentrating?
- C6
...washing or dressing?
- C7
...communicating in your usual language?
- C8
...feeding yourself?
- C9
...using the bathroom?
- C10
...waking up and getting out of bed?
- C11
...going out to the street?
- C12
...doing shopping or going to the doctor?
- C13
...manipulating small objects or opening a container?
- C14
...sleeping?
- C15
...breathing?
- C16
...doing household tasks like sweeping, cooking, arranging the house or taking out the trash?
- C17
...taking care of others?
- C18
...participating in community activities?
- C19
...feeling sad, down or depressed?
- C20
...feeling worried, nervous or anxious?
- C21
...getting along with people close to you, including your family and friends?
- C22
...coping with everything you have to do?
- C23
...feeling pain?
- C24
...getting things done in your job (if not currently working, NA)?
- C25
...getting things done at your school (if not currently studying, NA)?
Environmental factors section: On a scale from 1 (very easy) to 5 (very hard), to what extent...
- EF1
...do health facilities you need regularly make it easy or hard for you to use them?
- EF2
...do places where you socialize and engage in community activities make it easy or hard for you to do this?
- EF3
...do the shops, banks and post office in your neighbourhood make it easy or hard for you to use them?
- EF4
...do your regular places of worship make it easy or hard for you to worship?
- EF5
...does the transportation you need or want to use make it easy or hard for you to use it?
- EF6
...does your dwelling (including the toilet and all rooms) make it easy or hard for you to live there?
- EF7
...do the temperature, terrain, and climate of the place you usually live make it easy or hard for you to live there?
- EF8
...does the lighting in your surroundings make it easy or hard for you to live there?
- EF9
...does the noise in your surroundings make it easy or hard for you to live there?
- EF10
...do the crowds in your surroundings make it easy or hard for you to live there?
- EF11
...does your workplace make it easy or hard for you to work or learn (if not currently working, NA)?
- EF12
...does your educational institution make it easy or hard for you to work or learn (if not currently studying, NA)?
Example of WHO Model Disability Survey data for children
Description
An dummy data set of data from the WHO Model Disability Survey for children. All survey variables and demographic characterstics (except age variables) are randomly generated. Responses to the survey questions and age variables are from randomly selected rows of the 2014 Chilean implementation of the MDS, ENDIS II (2014).
Usage
df_children
Format
A tibble with 2500 rows and 42 variables:
- HHID
household number
- strata
survey strata
- PSU
PSU id
- weight
survey weights
- sex
sex, Male or Female
- age
age in years
- age_cat
age catgory, one of "Age2to4", "Age5to9", or "Age10to17"
Functioning section: On a scale from 1 (none) to 5 (extreme), in the last 30 days, taking into account any help or support the child receives, compared with children of the same age, how much has of a problem it been for the child to...
- child1
...walk?
- child2
...manipulat small objects or opening a container?
- child3
...see things from a long distance?
- child4
...hear?
- child5
...feel pain?
- child6
...not have enough energy?
- child7
...have too much energy
- child8
...feel short of breath?
- child9
...feel sad, down or depressed?
- child10
...feel worried, nervous or anxious?
- child11
...(for children aged 5 to 17) wash or dress him- or herself?
- child12
...(for children aged 2 to 4) bite or hit other children or adults?
- child13
...(for children aged 5 to 17) control his or her own behavior?
- child14
...(for children aged 5 to 17) get along with children of the same age?
- child15
...(for children aged 2 to 4) understand what you say to him or her?
- child16
(for children aged 2 to 4) How much of a problem has it been for you to understand what the child says?
- child17
...(for children aged 5 to 17) understand other people?
- child18
...(for children aged 5 to 17) be understood?
- child19
...(for children aged 2 to 3) learn the names of household objects?
- child20
...(for children aged 3 to 17) learn to do new things?
- child21
...(for children aged 5 to 17) complete a task?
- child22
...(for children aged 5 to 17) make changes to his or her routine?
- child23
...(for children aged 5 to 17) do homework as requested at school?
- child24
...(for children aged 2 to 5) play with toys or domestic objects?
- child25
...(for children aged 2 to 12) play with other children?
- child26
...(for children aged 13 to 17) do activities with other children?
- child27
...(for children aged 5 to 17) participate in community activities?
Capacity section: On a scale from 1 (none) to 5 (extreme), in the last 30 days, without taking into account any help or support the child receives, how much has difficulty has the child had with...
- child28
...seeing without glasses?
- child29
...hearing without hearing aids?
- child30
...walking?
- child31
...understanding you or others?
- child32
...learning?
- child33
...controling his or her behavior?
- child34
...completing a task?
- child35
...getting along with other children?
Print a graph showing significant correlations between survey items
Description
Print a graph showing significant correlations between survey items
Usage
fig_LID(
LIDforgraph,
LIDcutoff = 0.2,
path_output,
extra_file_label = NULL,
vertex_print_grey = NULL
)
Arguments
LIDforgraph |
a square matrix of item correlations |
LIDcutoff |
a numeric value between 0 and 1 for the cut-off for significant correlation |
path_output |
a string with the path to the output folder |
extra_file_label |
a string to tack on to the end of names of files outputted and the title of the plot. Default is NULL. |
vertex_print_grey |
a character vector with the names of vertices to print in |
Details
This function could be applied to visualize any kind of correlations. But within the context of the Rasch Analysis used for the WHO Model Disability Survey, the residual correlations are used when analyzing item dependence.
Value
Returns a ggplot graph showing the items with correlation >= LIDcutoff and prints a csv of the corresponding correlations
See Also
Other figure functions:
fig_density(),
fig_dist(),
fig_poppyramid()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# rasch_mds() also removes people with too many missing answers, here more
# than 2 of the 12 items. The model takes about 10 seconds on all 2500
# adults, so this example uses only the first 300 who remain
n_missing <- rowSums(is.na(df[items]))
df <- df[n_missing <= 2, ]
df <- df[1:300, ]
## Not run:
# the residual correlations between items come from rasch_model()
model <- rasch_model(df, items, vars_id = "HHID")
# draw the items whose residual correlation is 0.2 or more. A spreadsheet of
# these correlations is also saved in path_output, which must be a folder
# that already exists on your computer
fig_LID(model$LID, LIDcutoff = 0.2, path_output = "/Users/yourname/Desktop/Start")
## End(Not run)
Plot a density of a score
Description
Plot a density of a score
Usage
fig_density(
df,
score,
var_color = NULL,
var_facet = NULL,
cutoffs = NULL,
x_lab = "Score",
pal = "Paired",
adjust = 2,
size = 1.5
)
Arguments
df |
a data frame where each row is an individual, containing at least a score column (between 0 and 100) |
score |
a string (length 1) of the column name for the score variable to print the distribution of |
var_color |
a string (length 1) of the column name for the variable to set color of density lines by. Default is NULL. |
var_facet |
a string (length 1) of the column name for the variable to create a |
cutoffs |
a numeric vector of the cut-offs for the score categorization. Default is NULL. |
x_lab |
a string (length 1) of x-axis label. Default is "Score". |
pal |
a string specifying either a manual color to use for the color aesthetic, a character vector explictly specifying the colors to use for the color scale, or as the name of a palette to pass to |
adjust |
a numeric value to pass to |
size |
a numeric value for the width of the density lines, passed to the |
Details
Plots a histogram of a score that ranges between 0 and 100, with the fill determined by some set categorization of the score. This is the function used to plot the distributions of disability scores resulting from the WHO Model Disability Survey.
Value
A density figure
See Also
Other figure functions:
fig_LID(),
fig_dist(),
fig_poppyramid()
Examples
fig_density(df_adults, score = "disability_score", cutoffs = c(19.1, 34.4, 49.6),
x_lab = "Disability score")
fig_density(df_adults, score = "disability_score", var_color = "sex",
cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score")
fig_density(df_adults, score = "disability_score", var_color = "sex",
var_facet = "age_cat", cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score")
# derive the cut-offs from the score with helper_disability_cat()
cutoffs_derived <- attr(helper_disability_cat(df_adults$disability_score), "cutoffs")
fig_density(df_adults, score = "disability_score", cutoffs = cutoffs_derived,
x_lab = "Disability score")
Plot a distribution of a score
Description
Plot a distribution of a score
Usage
fig_dist(
df,
score,
score_cat,
cutoffs,
x_lab = "Score",
y_max = NULL,
pcent = FALSE,
pal = "Blues",
binwidth = 5
)
Arguments
df |
a data frame where each row is an individual, containing at least a score column (between 0 and 100) and a categorization of that score |
score |
a string (length 1) of the column name for the score variable to print the distribution of |
score_cat |
a string (length 1) of the column name for the categorization of the score variable |
cutoffs |
a numeric vector of the cut-offs for the score categorization |
x_lab |
a string (length 1) of x-axis label. Default is "Score". |
y_max |
a numeric value of the maximum limit on the y-axis. Default is NULL to use default value from |
pcent |
a logical value determining whether or not to display the distribution as percentages or frequency. Default is FALSE, to display as frequency. |
pal |
a string to pass to |
binwidth |
a numeric value giving the width of the bins in the histograph. Default is 5. |
Details
Plots a histogram of a score that ranges between 0 and 100, with the fill determined by some set categorization of the score. This is the function used to plot the distributions of disability scores resulting from the WHO Model Disability Survey.
Value
A score distribution figure with fill based on categorization of the score
See Also
Other figure functions:
fig_LID(),
fig_density(),
fig_poppyramid()
Examples
fig_dist(df_adults, score = "disability_score", score_cat = "disability_cat",
cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score")
fig_dist(df_adults, score = "disability_score", score_cat = "disability_cat",
cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score", y_max = 2000)
fig_dist(df_adults, score = "disability_score", score_cat = "disability_cat",
cutoffs = c(19.1, 34.4, 49.6), x_lab = "Disability score", y_max = 0.2, pcent=TRUE)
# derive the categories and their cut-offs from the score with helper_disability_cat()
df_cat <- dplyr::mutate(df_adults, disability_cat = helper_disability_cat(disability_score))
fig_dist(df_cat, score = "disability_score", score_cat = "disability_cat",
cutoffs = attr(df_cat$disability_cat, "cutoffs"), x_lab = "Disability score")
Print a population pyramid
Description
Print a population pyramid
Usage
fig_poppyramid(
df,
var_age,
var_sex,
x_axis = c("n", "pct"),
age_plus = 100,
age_by = 5
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
var_age |
a string (length 1) of the name of the age column |
var_sex |
a string (length 1) of the name of the sex column |
x_axis |
a string (length 1) indicating whether to use absolute numbers or sample percentage on the x-axis. Choices are |
age_plus |
a numeric value (length 1) indicating the age that is the first value of the oldest age group. Default is 100, for the last age group to be 100+ |
age_by |
a numeric value (length 1) indicating the width of each age group, in years. Default is 5. |
Details
A population pyramid gives an image of the age and sex distribution of a population.
The function divides the var_age variable into intervals of width age_by.
Value
A population pyramid figure
See Also
Other figure functions:
fig_LID(),
fig_density(),
fig_dist()
Examples
fig_poppyramid(df_adults, "age", "sex")
Check a vector for particular values
Description
Check a vector for particular values
Usage
helper_checkrow(
row,
check_type = c("all_equal", "all_not_equal", "any_in"),
check_value,
na_rm = TRUE
)
Arguments
row |
a vector of data |
check_type |
a string indicating the type of check to do on |
check_value |
a vector of values to check against |
na_rm |
logical indicating whether or not to perform check after removing NAs, passed to argument |
Details
If all values of row are NA, then an NA is returned.
Value
a logical vector with the result of the check
See Also
Other helper functions:
helper_disability_cat(),
helper_palette(),
helper_varslist()
Categorize a disability score into levels of disability
Description
Cuts a disability score, typically the rescaled score from
rasch_mds() or rasch_mds_children() ranging from 0 to 100,
into ordered levels of disability.
Usage
helper_disability_cat(
score,
cutoffs = NULL,
labels = c("No", "Mild", "Moderate", "Severe")
)
Arguments
score |
a numeric vector of scores |
cutoffs |
a numeric vector of strictly increasing cut-offs, with one
fewer element than |
labels |
a character vector of level names in increasing order of
disability. Default is |
Details
Each level includes its lower cut-off and excludes its upper one, so a score equal to a cut-off is assigned to the higher level. A score of exactly 0 is always assigned to the first level, even when the lowest cut-off is 0 or below. Missing scores give missing levels.
With the default cut-offs the levels are defined relative to the
population surveyed. This is how disability_cat in the example data
df_adults was created. Supply cutoffs explicitly to keep
levels comparable across surveys.
Value
an ordered factor the same length as score with levels
labels. The cut-offs used are stored in the attribute
"cutoffs", so they can be retrieved with
attr(x, "cutoffs") and passed to, for example, fig_dist().
See Also
Other helper functions:
helper_checkrow(),
helper_palette(),
helper_varslist()
Examples
disability_cat <- helper_disability_cat(df_adults$disability_score)
table(disability_cat)
attr(disability_cat, "cutoffs")
# fixed cut-offs and three levels
helper_disability_cat(c(0, 10, 50, 90), cutoffs = c(20, 60),
labels = c("Low", "Medium", "High"))
Create indicators from data frame
Description
Create indicators from data frame
Usage
helper_indicator(
df,
vars_indicators,
mapvalues_from,
mapvalues_to,
make_factor = TRUE
)
Arguments
df |
a data frame |
vars_indicators |
a character vector of the variables from |
mapvalues_from |
vector of values of |
mapvalues_to |
vector of replacement values, the same length as |
make_factor |
a logical indicating whether resulting indicators should be factors. Default is |
Value
a data frame with new columns that are the indicators from vars_indicators, with the same names pasted with "_ind".
Examples
helper_indicator(df = df_adults,
vars_indicators = c("EF1", "EF2", "EF3"),
mapvalues_from = 1:5,
mapvalues_to = c(0,0,0,1,1))
Check installation of whomds is the most updated
Description
Compares build date of installed package against the date of the last commit from GitHub (https://github.com/lindsayevanslee/whomds)
Usage
helper_installation()
Value
Prints a message stating whether or not installed package is same as most updated version from Github
Color palette for the MDS
Description
Color palette for the MDS
Usage
helper_palette(
n,
h = c(-100, 100),
c. = c(60, 100),
l = c(15, 95),
power = c(2, 0.9),
fixup = TRUE,
gamma = NULL,
alpha = 1,
...
)
Arguments
n |
the number of colors ( |
h |
hue value in the HCL or HSV color description, has to be in [0, 360] for HCL and in [0, 1] for HSV colors. |
c. |
chroma value in the HCL color description. |
l |
luminance value in the HCL color description. |
power |
control parameter determining how chroma and luminance should be increased (1 = linear, 2 = quadratic, etc.). |
fixup |
logical. Should the color be corrected to a valid RGB value before correction? |
gamma |
Deprecated. |
alpha |
numeric vector of values in the range |
... |
Other arguments passed to |
Details
Generated with colorspace::choose_palette()
Value
n hex codes from the color palette
See Also
Other helper functions:
helper_checkrow(),
helper_disability_cat(),
helper_varslist()
Perform row sum
Description
Perform row sum
Usage
helper_rowSums(x, allNA0 = TRUE, ...)
Arguments
x |
an array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame |
allNA0 |
logical indicating that if a whole row is NA to give the row sum as NA. Only works for two dimensional |
... |
other arguments to pass to |
Details
Essentially equivalent to base::rowSums() except with the addition of the allNA0 argument.
Value
A numeric or complex array of suitable size, or a vector if the result is one-dimensional.
Examples
x <- data.frame(v1 = c(NA,1:4), v2 = c(NA, 2:5), v3 = c(NA, 1:2, NA, 3))
helper_rowSums(x, na.rm = TRUE, allNA0 = TRUE)
helper_rowSums(x, na.rm = TRUE, allNA0 = FALSE)
Convert list to vector with unique elements
Description
Convert list to vector with unique elements
Usage
helper_varslist(vars_list)
Arguments
vars_list |
a list of character vectors |
Value
a character vector of all unique items from vars_list
See Also
Other helper functions:
helper_checkrow(),
helper_disability_cat(),
helper_palette()
Perform analysis of Differential Item Functioning (DIF) for Rasch Model
Description
Perform analysis of Differential Item Functioning (DIF) for Rasch Model
Usage
rasch_DIF(
df,
vars_metric,
vars_DIF,
residuals_PCM,
split_strategy = NULL,
print_results = FALSE,
path_output = NULL,
breaks = 6
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_DIF |
a string with the column names to use for analyzing differential item functioning (DIF). Default is NULL, to skip analysis of DIF. |
residuals_PCM |
a matrix giving the residuals of the person parameters from the Rasch Model. Row names are the numbers of the people and the columns are for each variable. |
split_strategy |
a named list giving the strategy to take for splitting variables by categories, passed to |
print_results |
a logical value indicating whether or not to print various files displaying results from the Rasch Model. Default is FALSE, to not print the files. |
path_output |
a string with the path to the output folder. Default is NULL. |
breaks |
a numeric value giving the number if class intervals. Default is 6. |
Details
Differential Item Functioning (DIF) refers to the circumstance when different groups in a sample respond to items in different ways. For instance, DIF would be observed if men and women had different patterns of responses to a set of survey questions. DIF can cause poor fit for the Rasch Model, and therefore should be analyzed. This function uses ANOVA to find DIF by the variables supplied and by a generated class interval.
Value
a list with results from the DIF analysis:
df_DIF_class |
the person residuals from the Rasch Model, the assigned class intervals, and the variables used for DIF analysis |
tab_aov_DIF |
the results of the ANOVA used to analyze DIF |
DIF_results |
string of various that exhibit some form of DIF |
Note
Currently the calculation of the class intervals is quite slow. Reducing the number of breaks can improve speed.
See Also
Other rasch functions:
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# rasch_mds() also removes people with too many missing answers, here more
# than 2 of the 12 items. The model takes about 10 seconds on all 2500
# adults, so this example uses only the first 300 who remain
n_missing <- rowSums(is.na(df[items]))
df <- df[n_missing <= 2, ]
df <- df[1:300, ]
# DIF analysis needs the person residuals from the Rasch Model
model <- rasch_model(df, items, vars_id = "HHID")
dif <- rasch_DIF(df, items, vars_DIF = c("sex", "age_cat"),
residuals_PCM = model$residuals_PCM)
# items whose responses differ by sex or age group, after accounting for
# the person's overall level of disability (empty when there is no DIF)
dif$DIF_results
# the ANOVA table behind that conclusion, one block per item and variable
head(dif$tab_aov_DIF)
Nest data by age group
Description
Nest data by age group
Usage
rasch_df_nest(df, vars_group, vars_id)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_group |
a string with the column name identifying grouping variable |
vars_id |
a string with column name uniquely identifying individuals |
Value
nested tibble with two columns: the age group given by vars_group and df_split with the split data
See Also
Other rasch functions:
rasch_DIF(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, "age_cat", vars_metric, "HHID", max_values)
# one row per age group, with that group's data in the column df_split
df_nest <- rasch_df_nest(split$df, vars_group = "age_cat", vars_id = "HHID")
df_nest
head(df_nest$df_split[[1]][1:6])
Drop items from a Rasch Analysis
Description
Drop items from a Rasch Analysis
Usage
rasch_drop(vars_metric, drop_vars, max_values)
Arguments
vars_metric |
a character vector of items to use in the Rasch Analysis |
drop_vars |
a character vector of column names to drop from the Rasch Analysis. Default is NULL, to not drop items. |
max_values |
a tibble with two columns, |
Details
Dropping variables might be desirable if one finds that particular items are causing a lot of problems for the fit of a Rasch Model.
Value
a named list with:
vars_metric |
new |
max_values |
new |
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# Remove EF11 and EF12 from the scale, for example because they fit poorly
dropped <- rasch_drop(items, drop_vars = c("EF11", "EF12"), max_values = max_values)
dropped$vars_metric
dropped$max_values
Calculate a factor analysis for a Rasch Model
Description
Calculate a factor analysis for a Rasch Model
Usage
rasch_factor(df, vars_metric, print_results = FALSE, path_output = NULL)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
print_results |
a logical value indicating whether or not to print various files displaying results from the Rasch Model. Default is FALSE, to not print the files. |
path_output |
a string with the path to the output folder. Default is NULL. |
Details
Unidimensionality of the data is one of the core assumptions of the Rasch Model. This function performs the factor analysis to assess the unidimensionality of the data.
Value
a named list with results from the factor analysis for a Rasch Model:
cor_poly |
the matrix of polychoric correlations |
eigenvalues |
the eigenvalues |
parallel_analysis |
permutation parallel analysis distribution |
results_scree |
results of a scree analysis |
n_group_factors |
number of factors from the parallel analysis in the scree analysis |
fa_onefactor |
results from factor analysis with one factor |
fa_resid |
local dependency based on polychoric correlations of the items |
Note
psych is listed in Depends rather than Imports on purpose. The bifactor
rotation in psych::fa() is carried out by GPArotation::GPForth(),
which looks up the rotation criterion vgQ.bimin by name on the search
path. If psych is only loaded and not attached, that lookup fails and the
bifactor model is silently skipped. Tested with psych 2.6.9 and
GPArotation 2026.8.2.
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# (warnings that a polychoric correlation "removed a row with zero marginal"
# are expected here: few people answered EF12, so some of its response
# options are never seen together with those of other items)
factors <- rasch_factor(df, items)
# the Rasch Model assumes the items measure one single thing (they are
# "unidimensional"); the parallel analysis suggests how many factors there are
factors$n_group_factors
# a first eigenvalue much larger than the rest also points to one dimension
round(factors$eigenvalues, 2)
# the one-factor model shows how strongly each item relates to that factor
factors$fa_onefactor$loadings
Top-level function to perform Rasch Analysis on WHO Model Disability Survey data
Description
Top-level function to perform Rasch Analysis on WHO Model Disability Survey data
Usage
rasch_mds(
df,
vars_metric,
vars_id,
vars_DIF = NULL,
resp_opts = 1:5,
max_NA = 2,
print_results = FALSE,
path_parent = NULL,
model_name = NULL,
testlet_strategy = NULL,
recode_strategy = NULL,
drop_vars = NULL,
split_strategy = NULL,
comment = NULL
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_id |
a string with column name uniquely identifying individuals |
vars_DIF |
a string with the column names to use for analyzing differential item functioning (DIF). Default is NULL, to skip analysis of DIF. |
resp_opts |
a numeric vector of possible response options for |
max_NA |
a numeric value for the maximum number of NAs allowed per individual among |
print_results |
a logical value indicating whether or not to print various files displaying results from the Rasch Model. Default is FALSE, to not print the files. |
path_parent |
a string with the path to the folder where results from multiple models will be outputted. Default is NULL |
model_name |
a string with a name for the model, which is used to create a new folder for model output. Default is NULL. |
testlet_strategy |
a list giving the strategy to take for creating testlets, passed to |
recode_strategy |
a named list giving the strategy to take for recoding variables, passed to |
drop_vars |
a character vector of column names to drop from the Rasch Analysis. Default is NULL, to not drop items. |
split_strategy |
a named list giving the strategy to take for splitting variables by categories, passed to |
comment |
a string giving a comment describing the analysis, printed to a txt file. Default is NULL, to not print a comment. |
Details
This function combines all of the separate analyses of model fit necessary to assess the quality of the Rasch Model. It is designed to require minimal intervention from the user. Users wishing to have more control over the analysis can use the other Rasch functions in this package separately.
Value
a named list with:
df |
a tibble with new columns representing the original person abilities ( |
vars_metric |
a character vector with the variables used in the metric after all adjustments |
df_results |
a tibble of one row with key results of the model |
If print_results is TRUE, prints files to the working directory with the results of the Rasch Model.
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# One iteration of Rasch Analysis on the 12 environmental factor items of
# the example adult data, checking for differential item functioning (DIF)
# by sex and age group. This takes about 15 seconds. No files are saved
# because print_results is FALSE
start <- rasch_mds(
df = df_adults,
vars_metric = paste0("EF", 1:12),
vars_id = "HHID",
vars_DIF = c("sex", "age_cat"),
resp_opts = 1:5,
max_NA = 2,
print_results = FALSE
)
# the data with each person's ability ("person_pars"), its standard error
# and the ability rescaled to a 0 to 100 disability score
head(start$df[c("HHID", "person_pars", "person_pars_se", "rescaled")])
# a one-row summary of how well the data fit the model
start$df_results
## Not run:
# To save the full set of results (plots, spreadsheets and the scored data)
# on your computer, set print_results to TRUE and give a folder that already
# exists, ending in "/". A new folder named after model_name is created
# inside it. On Windows the path looks like "C:/Users/yourname/Desktop/"
start <- rasch_mds(
df = df_adults,
vars_metric = paste0("EF", 1:12),
vars_id = "HHID",
vars_DIF = c("sex", "age_cat"),
resp_opts = 1:5,
max_NA = 2,
print_results = TRUE,
path_parent = "/Users/yourname/Desktop/",
model_name = "Start",
comment = "Initial run with all 12 items"
)
## End(Not run)
Top-level function to perform Rasch Analysis on WHO Model Disability Survey data for children
Description
Top-level function to perform Rasch Analysis on WHO Model Disability Survey data for children
Usage
rasch_mds_children(
df,
vars_id,
vars_group,
vars_metric_common,
vars_metric_grouped = NULL,
TAM_model = "PCM2",
vars_DIF = NULL,
resp_opts = 1:5,
has_at_least_one = 4:5,
max_NA = 2,
print_results = FALSE,
path_parent = NULL,
model_name = NULL,
testlet_strategy = NULL,
recode_strategy = NULL,
drop_vars = NULL,
split_strategy = NULL,
comment = NULL
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_id |
a string with column name uniquely identifying individuals |
vars_group |
a string with the column name identifying grouping variable |
vars_metric_common |
a character vector the common items among all individuals |
vars_metric_grouped |
a named list of character vectors with the items to use in the Rasch Analysis per group. The list should have names corresponding to the different groups, and contain character vectors of the corresponding items for each group. |
TAM_model |
a string with the type of IRT model to use, passed to |
vars_DIF |
Currently does nothing. In the future, a string with the column names to use for analyzing differential item functioning (DIF). Default is NULL, to skip analysis of DIF. |
resp_opts |
a numeric vector of possible response options for |
has_at_least_one |
a numeric vector with the response options that a respondent must have at least one of in order to be included in the metric calculation. See details for more information. |
max_NA |
a numeric value for the maximum number of NAs allowed per individual among |
print_results |
a logical value indicating whether or not to print various files displaying results from the Rasch Model. Default is FALSE, to not print the files. |
path_parent |
a string with the path to the folder where results from multiple models will be outputted. Default is NULL |
model_name |
a string with a name for the model, which is used to create a new folder for model output. Default is NULL. |
testlet_strategy |
a list giving the strategy to take for creating testlets, passed to |
recode_strategy |
a named list giving the strategy to take for recoding variables, passed to |
drop_vars |
a character vector of column names to drop from the Rasch Analysis. Default is NULL, to not drop items. |
split_strategy |
a named list giving the strategy to take for splitting variables by categories, passed to |
comment |
a string giving a comment describing the analysis, printed to a txt file. Default is NULL, to not print a comment. |
Details
This function combines all of the separate analyses of model fit necessary to assess the quality of the Rasch Model. It is designed to require minimal intervention from the user. Users wishing to have more control over the analysis can use the other Rasch functions in this package separately.
Often Rasch Analysis of children data is more difficult because of the extreme skewness of the responses. For this reason, it is often advisable to build a scale only with the respondents on the more severe end of the disability continuum. By specifying has_at_least_one, the function will remove all children from the sample who do endorse an answer of any of has_at_least_one in at least one vars_metric. The scores created can be reunited with the excluded children post-hoc.
Value
a tibble with new columns representing the original person abilities (person_pars), their standard errors (person_pars_se, on the same logit scale) and the rescaled person abilities (rescaled).
If print_results is TRUE, prints files to the working directory with the results of the Rasch Model.
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# One iteration of Rasch Analysis on the example children data. Ten items
# were asked of every child and the others only of certain age groups, so
# the items are given in two parts. Only children with at least one answer
# of 4 or 5 are used (has_at_least_one), which is usual for children data.
# No files are saved because print_results is FALSE
start <- rasch_mds_children(
df = df_children,
vars_id = "HHID",
vars_group = "age_cat",
vars_metric_common = paste0("child", 1:10),
vars_metric_grouped = list(
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
),
TAM_model = "PCM2",
resp_opts = 1:5,
has_at_least_one = 4:5,
max_NA = 10,
print_results = FALSE
)
# the data with each child's ability ("person_pars"), its standard error and
# the ability rescaled to a 0 to 100 disability score
head(start$df[c("HHID", "age_cat", "person_pars", "person_pars_se", "rescaled")])
# the items used for each age group; items asked of more than one group
# have been split into one item per group
start$vars_metric
# To save plots and spreadsheets of the results on your computer, add
# print_results = TRUE, path_parent = "/Users/yourname/Desktop/" (a folder
# that already exists, ending in "/") and model_name = "Start", as in the
# example for rasch_mds()
Run the Rasch Model and print diagnostic results
Description
Run the Rasch Model and print diagnostic results
Usage
rasch_model(
df,
vars_metric,
vars_id,
print_results = FALSE,
path_output = NULL,
LIDcutoff = 0.2
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_id |
a string with column name uniquely identifying individuals |
print_results |
a logical value indicating whether or not to print various files displaying results from the Rasch Model. Default is FALSE, to not print the files. |
path_output |
a string with the path to the output folder. Default is NULL. |
LIDcutoff |
either a numeric value between 0 and 1 indicating the cut-off for significant local item dependence, or the string "christensen" to use the cut-off suggested by Christensen et al. 2017 (see reference). If "christensen" cut-off fails, defaults to 0.2. |
Details
The Rasch Model is calculated using the function eRm::PCM().
Value
a list with results from the Rasch Model:
model |
the results from the Rasch Model |
df_score |
a tibble with the items used in the analysis, the person abilities ( |
thresholds |
the item thresholds (i.e., crossings) |
person_parameters |
person abilities |
PSI |
the person-separation index |
item_fit |
infit and outfit statistics per item |
residuals_PCM |
the standardized person residuals |
LID |
matrix with the item residual correlations |
targeting |
a matrix with information on the targeting of the model |
fit_results |
a string with results of the item fit |
LID_results |
a string with results of the local item dependency |
disordered_results |
a string listing items with disordered thresholds |
References
Christensen, K. B., Makransky, G., & Horton, M. (2017). Critical Values for Yen’s Q 3 : Identification of Local Dependence in the Rasch Model Using Residual Correlations. Applied Psychological Measurement, 41(3), 178-194. doi:10.1177/0146621616677520
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# rasch_mds() also removes people with too many missing answers, here more
# than 2 of the 12 items. The model takes about 10 seconds on all 2500
# adults, so this example uses only the first 300 who remain
n_missing <- rowSums(is.na(df[items]))
df <- df[n_missing <= 2, ]
df <- df[1:300, ]
model <- rasch_model(df, items, vars_id = "HHID")
# summaries of how well the data fit the model (see the package vignettes
# for how to interpret them)
model$fit_results # items that fit, underfit or overfit
model$LID_results # pairs of items that are locally dependent
model$disordered_results # items with disordered thresholds
model$PSI # person separation index, the reliability
# each person's ability estimate ("person_pars") and its standard error
head(model$df_score)
Run the multigroup and anchored Rasch Model
Description
Run the multigroup and anchored Rasch Model
Usage
rasch_model_children(df, df_nest, vars_metric, vars_group, TAM_model)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
df_nest |
a nested tibble that contains the column |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_group |
a string with the column name identifying grouping variable |
TAM_model |
a string with the type of IRT model to use, passed to |
Value
a nested tibble with new columns with the Rasch Models calculated with the TAM package
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, "age_cat", vars_metric, "HHID", max_values)
df_nest <- rasch_df_nest(split$df, "age_cat", "HHID")
df_nest <- rasch_model_children(split$df, df_nest, split$vars_metric,
vars_group = "age_cat", TAM_model = "PCM2")
# new columns hold the models: a "multigroup" model fitted to all age groups
# together and an "anchored" model for each age group
names(df_nest)
df_nest$mod_multigroup[[1]]
Calculate quality of multigroup and anchored Rasch Models
Description
Calculate quality of multigroup and anchored Rasch Models
Usage
rasch_quality_children(df_nest, vars_metric)
Arguments
df_nest |
a nested tibble that contains the column |
vars_metric |
a character vector of items to use in the Rasch Analysis |
Value
a nested tibble with new columns with information about model quality
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, "age_cat", vars_metric, "HHID", max_values)
df_nest <- rasch_df_nest(split$df, "age_cat", "HHID")
df_nest <- rasch_model_children(split$df, df_nest, split$vars_metric,
vars_group = "age_cat", TAM_model = "PCM2")
df_nest <- rasch_quality_children(df_nest, split$vars_metric)
# new columns hold the quality measures for each model, for example the
# item fit and the residual correlations ("cor") of the multigroup model
names(df_nest)
head(df_nest$itemfit_multigroup[[1]])
Print results of analysis of Rasch Model quality
Description
Print results of analysis of Rasch Model quality
Usage
rasch_quality_children_print(
df_nest,
vars_metric,
vars_group,
TAM_model,
LIDcutoff = 0.2,
path_output
)
Arguments
df_nest |
a nested tibble that contains the column |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_group |
a string with the column name identifying grouping variable |
TAM_model |
a string with the type of IRT model to use, passed to |
LIDcutoff |
a numeric value between 0 and 1 for the cut-off for significant correlation |
path_output |
a string with the path to the output folder |
Value
does not return anything to the environment, but prints files to the folder specified in path_output
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, "age_cat", vars_metric, "HHID", max_values)
df_nest <- rasch_df_nest(split$df, "age_cat", "HHID")
df_nest <- rasch_model_children(split$df, df_nest, split$vars_metric,
vars_group = "age_cat", TAM_model = "PCM2")
df_nest <- rasch_quality_children(df_nest, split$vars_metric)
## Not run:
# save spreadsheets and plots of the quality measures in path_output, which
# must be a folder that already exists on your computer
rasch_quality_children_print(df_nest, split$vars_metric, vars_group = "age_cat",
TAM_model = "PCM2", path_output = "/Users/yourname/Desktop/Start")
## End(Not run)
Add the raw scores to the data and artificial individuals attaining the minimum and/or maximum
Description
Add the raw scores to the data and artificial individuals attaining the minimum and/or maximum
Usage
rasch_rawscore(df, vars_metric, vars_id, max_values)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_id |
a string with column name uniquely identifying individuals |
max_values |
a tibble with two columns, |
Value
a tibble with a new column RawScore with the raw sum score of vars_metric for each individual, and artificial rows with individuals that attain the minimum and/or maximum if either is not attained in df. The artificial maximum row has value "MAX" in the vars_id column, and likewise the artificial minimum row has the value "MIN" in this column.
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
df_raw <- rasch_rawscore(df, items, vars_id = "HHID", max_values = max_values)
# each person's raw score is the sum of their responses
head(df_raw[c("HHID", items, "RawScore")])
# nobody in df_adults answered 4 to every item, so an artificial person with
# ID "MAX" and the highest possible score is added at the end of the data.
# Someone already has the lowest score, so no "MIN" person is needed
tail(df_raw[c("HHID", items, "RawScore")], 2)
Recode survey items for use in Rasch Analysis
Description
Recode survey items for use in Rasch Analysis
Usage
rasch_recode(df, vars_metric, recode_strategy, max_values)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
recode_strategy |
a named list giving the strategy to take for recoding variables, passed to |
max_values |
a tibble with two columns, |
Value
a named list with:
df |
new |
max_values |
new |
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# Collapse the response options of EF1 and EF2 so that the two highest
# options (3 and 4 after the shift) become one, and those of EF3 from five
# options to three
recoded <- rasch_recode(df, items,
recode_strategy = list("EF1,EF2" = c(0, 1, 2, 3, 3), "EF3" = c(0, 1, 1, 2, 2)),
max_values = max_values)
# compare the original and recoded responses to EF1
table(original = df$EF1, recoded = recoded$df$EF1)
# the highest possible values of the recoded items are updated
recoded$max_values
Rescale score from Rasch Analysis to range from 0 to 100
Description
Rescale score from Rasch Analysis to range from 0 to 100
Usage
rasch_rescale(df, df_score, vars_id)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
df_score |
a tibble resulting from |
vars_id |
a string with column name uniquely identifying individuals |
Value
a tibble with the left join between df and df_score (which carries person_pars and person_pars_se) and new column rescaled with the rescaled person abilities, ranging from 0 to 100, with any rows with an artificial minimum or maximum filtered out
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# rasch_mds() also removes people with too many missing answers, here more
# than 2 of the 12 items. The model takes about 10 seconds on all 2500
# adults, so this example uses only the first 300 who remain
n_missing <- rowSums(is.na(df[items]))
df <- df[n_missing <= 2, ]
df <- df[1:300, ]
model <- rasch_model(df, items, vars_id = "HHID")
df_final <- rasch_rescale(df, model$df_score, vars_id = "HHID")
# the person abilities are on a logit scale; "rescaled" puts them on the
# 0 to 100 disability score used in WHO reports
head(df_final[c("HHID", "person_pars", "person_pars_se", "rescaled")])
range(df_final$rescaled)
Rescale score from Rasch Analysis for children to range from 0 to 100
Description
Rescale score from Rasch Analysis for children to range from 0 to 100
Usage
rasch_rescale_children(df, df_nest, vars_group, vars_id)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
df_nest |
a nested tibble that contains the column |
vars_group |
a string with the column name identifying grouping variable |
vars_id |
a string with column name uniquely identifying individuals |
Value
a tibble with the data df or unnested df_nest and new columns person_pars (person abilities), person_pars_se (their standard errors, on the same logit scale) and rescaled (abilities rescaled to range from 0 to 100), with any rows with an artificial minimum or maximum filtered out
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_split(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, "age_cat", vars_metric, "HHID", max_values)
df_nest <- rasch_df_nest(split$df, "age_cat", "HHID")
df_nest <- rasch_model_children(split$df, df_nest, split$vars_metric,
vars_group = "age_cat", TAM_model = "PCM2")
df_nest <- rasch_quality_children(df_nest, split$vars_metric)
df_final <- rasch_rescale_children(split$df, df_nest, vars_group = "age_cat",
vars_id = "HHID")
# each child's ability ("person_pars"), its standard error and the ability
# rescaled to a 0 to 100 disability score
head(df_final[c("HHID", "age_cat", "person_pars", "person_pars_se", "rescaled")])
Split survey items by categories for a Rasch Model
Description
Split survey items by categories for a Rasch Model
Usage
rasch_split(df, vars_metric, split_strategy, max_values)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
split_strategy |
a named list giving the strategy to take for splitting variables by categories, passed to |
max_values |
a tibble with two columns, |
Details
If significant differential item functioning (DIF) is observed, it may be desirable to split variables based on the characteristic for which DIF is observed. For example, if men and women have significantly different patterns of responses to items, then it may be desirable to split items by sex. This function performs that variable splitting.
Value
a named list with:
df |
new |
vars_metric |
new |
max_values |
new |
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split_age(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split_age(),
rasch_testlet()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# Split EF1 and EF2 by sex, so that each becomes two items: one answered
# only by women and one only by men
split <- rasch_split(df, items, split_strategy = list(sex = c("EF1", "EF2")),
max_values = max_values)
# the split items replace the originals in the list of items ...
split$vars_metric
# ... and in the data, where each new item is missing for the other sex
head(split$df[c("sex", "EF1_Female", "EF1_Male")])
Split all survey items by age category for a Rasch Model if they are not discrete
Description
Split all survey items by age category for a Rasch Model if they are not discrete
Usage
rasch_split_age(df, vars_group, vars_metric, vars_id, max_values)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_group |
a string with the column name identifying grouping variable |
vars_metric |
a character vector of items to use in the Rasch Analysis |
vars_id |
a string with column name uniquely identifying individuals |
max_values |
a tibble with two columns, |
Value
a named list with:
df |
new |
vars_metric |
new |
max_values |
new |
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_testlet()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_testlet()
Examples
# rasch_mds_children() prepares the survey data before calling this function.
# To use the function on its own, do the same preparation by hand:
# 1. list the items: those asked of every child ("common") and those asked
# only of children in a particular age group
vars_metric <- list(
common = paste0("child", 1:10),
Age2to4 = paste0("child", c(12, 15, 16, 19, 20, 24, 25)),
Age5to9 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25, 27)),
Age10to17 = paste0("child", c(11, 13, 14, 17, 18, 20, 21, 22, 23, 25, 26, 27))
)
items <- unique(unlist(vars_metric))
df <- df_children
# 2. make the ID column text
df$HHID <- as.character(df$HHID)
# 3. shift the responses 1 to 5 down to 0 to 4; any other code (such as 88
# for "don't know") becomes missing
df[items] <- lapply(df[items], function(x) ifelse(x %in% 1:5, x - 1, NA))
# 4. keep only children with at least one answer of 4 or 5 (3 or 4 after the
# shift), as rasch_mds_children() does by default (see has_at_least_one)
df <- df[rowSums(df[items] >= 3, na.rm = TRUE) > 0, ]
# 5. record the highest possible value of each item
max_values <- data.frame(var = items, max_val = 4)
split <- rasch_split_age(df, vars_group = "age_cat", vars_metric = vars_metric,
vars_id = "HHID", max_values = max_values)
# items asked of more than one age group (child11 is asked of ages 5 to 17)
# are split into one item per age group, so each can have its own difficulty
split$vars_metric$Age5to9
head(split$df[c("age_cat", "child11", "child11_Age5to9", "child11_Age10to17")])
Create testlets of survey items for a Rasch Model
Description
Create testlets of survey items for a Rasch Model
Usage
rasch_testlet(df, vars_metric, testlet_strategy, max_values, resp_opts)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_metric |
a character vector of items to use in the Rasch Analysis |
testlet_strategy |
a list giving the strategy to take for creating testlets, passed to |
max_values |
a tibble with two columns, |
resp_opts |
a numeric vector of possible response options for |
Details
If high local item dependence is observed (i.e., residual correlation) is observed between items, it may be desirable to combine them into a testlet. This code creates the testlets as desired.
Value
a named list with:
df |
new |
vars_metric |
new |
testlet_strategy |
new |
max_values |
new |
See Also
Other rasch functions:
rasch_DIF(),
rasch_df_nest(),
rasch_drop(),
rasch_factor(),
rasch_mds(),
rasch_mds_children(),
rasch_model(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_rawscore(),
rasch_recode(),
rasch_rescale(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age()
Other children analysis functions:
rasch_df_nest(),
rasch_drop(),
rasch_mds_children(),
rasch_model_children(),
rasch_quality_children(),
rasch_quality_children_print(),
rasch_recode(),
rasch_rescale_children(),
rasch_split(),
rasch_split_age()
Examples
# rasch_mds() prepares the survey data before calling this function. To use
# the function on its own, do the same preparation by hand:
# 1. choose the items (survey questions) that will make up the scale
items <- paste0("EF", 1:12)
# 2. shift the responses 1 to 5 down to 0 to 4, as the Rasch Model expects
df <- df_adults
df[items] <- df[items] - 1
# 3. make the ID column text, so that the artificial IDs "MIN" and "MAX" can
# be added to it later
df$HHID <- as.character(df$HHID)
# 4. record the highest possible value of each item (5, or 4 after the shift)
max_values <- data.frame(var = items, max_val = 4)
# Combine EF4, EF6 and EF8 into one testlet named "new", and EF5 and EF7
# into another. The second testlet is not named, so it is called "EF5_EF7"
testlets <- rasch_testlet(df, items,
testlet_strategy = list(new = c("EF4", "EF6", "EF8"), c("EF5", "EF7")),
max_values = max_values, resp_opts = 1:5)
# the testlets replace their items in the list of items ...
testlets$vars_metric
# ... and in the data, where a testlet is the sum of its items
head(testlets$df[c("EF4", "EF6", "EF8", "new")])
# a testlet of three items with values 0 to 4 can reach 12
testlets$max_values
Compute basic statistics of the number of members per group per household
Description
Compute basic statistics of the number of members per group per household
Usage
table_basicstats(df, hh_id, group_by_var)
Arguments
df |
a data frame of household data where the rows represent members of the households in the sample |
hh_id |
string (length 1) indicating the name of the variable in |
group_by_var |
string (length 1) to pass to |
Value
A tibble with rows for each level of group_by_var and "Total" and columns for the Mean (SD), Median and Range of the number of people in each group per household.
Note
Includes a call to tidyr::complete(), which causes the function to be a bit slow.
See Also
Other table functions:
table_unweightedpctn(),
table_weightedpct()
Examples
#create dummy table of household data, where each row represents one member
df_hh <- data.frame(HHID = sample(
x = 1:300,
size = 1000,
replace = TRUE
),
age_cat = ordered(sample(
x = c("18-24", "25-39", "40-64", "64-100"),
size = 1000,
replace = TRUE
)))
table_basicstats(df_hh, "HHID", "age_cat")
Compute unweighted percent and N for multiple variables, disaggregated
Description
Compute unweighted percent and N for multiple variables, disaggregated
Usage
table_unweightedpctn(
df,
vars_demo,
group_by_var = NULL,
spread_by_group_by_var = FALSE,
group_by_var_sums_to_100 = FALSE,
add_totals = FALSE
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_demo |
a character vector of names of variables to calculate percent and N for |
group_by_var |
a string (length 1) with the name of the variable from |
spread_by_group_by_var |
logical determining whether to pass |
group_by_var_sums_to_100 |
logical determining whether percentages sum to 100 along the margin of |
add_totals |
logical determining whether to create total rows or columns (as appropriate) that demonstrate the margin that sums to 100. Default is FALSE. |
Value
A tibble with percent and N for each level of each variable in vars_demo
See Also
Other table functions:
table_basicstats(),
table_weightedpct()
Examples
table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat"))
table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat"),
group_by_var = "disability_cat")
table_unweightedpctn(df_adults, vars_demo = c("sex", "age_cat", "work_cat", "edu_cat"),
group_by_var = "disability_cat", spread_by_group_by_var = TRUE)
Calculate table of percentages or N of response distribution for survey items, survey weighted, disaggregated
Description
Calculate table of percentages or N of response distribution for survey items, survey weighted, disaggregated
Usage
table_weightedpct(
df,
vars_ids,
vars_strata,
vars_weights,
formula_vars,
...,
formula_vars_levels = 0:1,
by_vars = NULL,
pct = TRUE,
willfilter = NULL,
add_totals = FALSE,
spread_key = NULL,
spread_value = "prop",
arrange_vars = NULL,
include_SE = FALSE
)
Arguments
df |
a data frame of individual survey data, where each row is an individual |
vars_ids |
a character vector of cluster ids, passed to |
vars_strata |
a character vector of strata ids, passed to |
vars_weights |
a character vector of survey weight ids, passed to |
formula_vars |
a character vector of variables to calculate the percentages of each level for |
... |
captures expressions to pass to |
formula_vars_levels |
a vector of the levels of the the |
by_vars |
a character vector of variables to disaggregate results by. Default is |
pct |
a logical variable indicating whether or not to calculate weighted percentages. Default is |
willfilter |
a logical variable that tells the function whether or not to filter or transmute the data. Leave as default |
add_totals |
logical determining whether to create total rows or columns (as appropriate) that demonstrate the margin that sums to 100. Default is FALSE. |
spread_key |
a string with variable name to pass to |
spread_value |
a string with variable name to pass to |
arrange_vars |
a character vector with variables to pass to |
include_SE |
a logical variable indicating whether to include the standard errors in the table. Default is FALSE. Currently does not work when adding totals, spreading or transmuting. |
Details
If willfilter is NULL, the table is not filtered or transmuted. If willfilter is TRUE, the table is filtered before it is spread or arranged. If willfilter is FALSE, the table is transmuted after the spread and/or arrange. "..." captures the non-standard evaluation expressions (NSE) to pass to dplyr::filter or dplyr::transmute().
The function performs the following actions with the table after results are calculated in the following order (if applicable): filter, add totals, spread, arrange, transmute
Value
a tibble of weighted response percentages or N's
See Also
See vignette("programming", package = "dplyr") for more about non-standard evaluation (NSE)
Other table functions:
table_basicstats(),
table_unweightedpctn()
Examples
table_weightedpct(df_adults,
vars_ids = c("HHID", "PSU"),
vars_strata = "strata",
vars_weights = "weight",
formula_vars = paste0("EF",1:10),
formula_vars_levels = 1:5,
by_vars = "sex")