Learn R Programming

parsec (version 1.1.1)

var2prof: Variables to profiles

Description

The function produces the list of all of the profiles from a list of input ordinal variables. See details for how to define variables.

Usage

var2prof(varmod = lapply(as.list(varlen), function(x) 1:x),
    varlen = sapply(varmod, length), freq = NULL,
    labtype = c("profiles", "progressive"), y=NULL)

Arguments

varmod
list of variables and their modalities. See details.
varlen
a vector of number of modalities of each variable. See details.
freq
profiles frequency distribution. By default, the frequencies are set equal to 1.
labtype
type of labels to assign to profiles. See details.
y
a matrix of observations, used to count profiles frequencies. See details.

Value

  • The function returns a S3 class object wprof, "weighted profiles", comprising the data.frame profiles and the vector of frequencies freq.

Details

Variables can be defined through their names and modalities, using a list as argument varmod. The names of the objects in the list are taken as variable names. The objects in the list must be ordered vectors or numeric vectors. A faster way to define variables is through a vector with the number of modalities of each variable, as argument varlen. This way, variables and ttheir modalities are assigned arbitrary names. In particular, modalities are identified by their ranks in variable definition. The user can choose the type label to assign to profiles. profiles is the combination of modailties identifying the profiles. When the names of the modalities are too long, it is suggested to choose progressive. y is a matrix of observation on the ordinal variables (observations by rows and variables by columns). Variables must be ordered as defined in the previous parameters. The names of variable modalities must match their definition. By this parameter, the function counts the number of times a profile is observed in the population, assigning the result to the freq output parameter. This method should be used when the variables and their modalities are known, otherwise the function pop2prof is available.

See Also

pop2prof, getzeta

Examples

Run this code
# 2 variables with 2 modalities, frequencies detected from population
pop <- matrix(sample(1:2, 200, replace=TRUE), 50, 2)
var2prof(varlen=c(2, 2))

# 2 variables:
# - mood: 2 modalities
# - weather: 3 modalities
# 2*3 profiles and frequencies sampled from a Binomial distribution n = 10, p = 0.5
var <- list(
    mood = ordered(c("bad", "good"), levels = c("bad", "good")),
    weather = ordered(c("rainy", "cloudy", "sunny"), levels = c("rainy", "cloudy", "sunny"))
)
var2prof(var, freq = rbinom(2*3, 10, 0.5), labtype = "progressive")

Run the code above in your browser using DataLab