Learn R Programming

missalpha (version 0.2.0)

generate_scores_mat_bernoulli: Generate Bernoulli Distributed Scores Matrix with Missing Values

Description

This function generates a matrix of scores for a set of people and items, where the scores are generated using a Bernoulli distribution with person-specific probabilities. It also allows for some scores to be missing (represented by NA).

Usage

generate_scores_mat_bernoulli(n_person, n_item, n_missing, score_max = 1)

Value

A matrix of size n_person by n_item containing generated scores (0 or score_max) with some values replaced by NA to simulate missing data.

Arguments

n_person

An integer representing the number of people (rows in the matrix).

n_item

An integer representing the number of items (columns in the matrix).

n_missing

An integer representing the number of missing scores (set to NA in the matrix).

score_max

An integer representing the largest possible score for any item. Default is 1.

Details

The function generates a score matrix where each person's score for each item is drawn from a Bernoulli distribution with a person-specific probability. A number of scores are set to NA to simulate missing values.

The probability of each person scoring on the items is determined by randomly generating a probability for each person using runif. The Bernoulli distribution is then used (via rbinom) to generate the scores, and NA values are assigned to randomly selected positions in the matrix based on n_missing.

Examples

Run this code
# Generate a 10x5 score matrix with 10 missing values and maximum score of 1
scores_mat <- generate_scores_mat_bernoulli(10, 5, 10, score_max = 1)
print(scores_mat)

Run the code above in your browser using DataLab