Learn R Programming

factorMerger (version 0.4.0)

mergeFactors: Merge factors

Description

Performs step-wise merging of factor levels.

Usage

mergeFactors(response, factor, ...)

Arguments

response

A response vector/matrix suitable for the model family or a formula containing columns names from the data argument or formula.

factor

A factor vector when we use response argument, otherwise the name of column from data argument containing which levels should be merged.

...

Other arguments corresponding to type of first argument

Examples

Run this code
# NOT RUN {
rSample <- generateMultivariateSample(N = 100, k = 10, d = 3)

rSample$covariates <- runif(100)
rSample$weights <- runif(100)
mergeFactors(response = rSample$response, factor = rSample$factor)
mergeFactors(response = rSample$response, factor = rSample$factor, 
    covariates = rSample$covariates)
mergeFactors(rSample$response[,1], rSample$factor, 
    covariates = rSample$covariates, weights = rSample$weights)
dataset <- cbind(rSample$response, rSample$factor, rSample$covariates)
colnames(dataset) <- c("res1","res2","res3","fct", "cov1")

formula <- as.formula("res1+res2+res3~fct")
formulaCovariates <-as.formula("res1+res2+res3~fct+cov1")
mergeFactors(response = formula, factor="fct", data=dataset)
mergeFactors(response = formulaCovariates, factor="fct", data=dataset)

# }

Run the code above in your browser using DataLab