weighted_factor_sim: Compute Weighted Similarity Matrix for Factors in a Data...

View source: R/knn_weights.R

weighted_factor_simR Documentation

Compute Weighted Similarity Matrix for Factors in a Data Frame

Description

Calculate the weighted similarity matrix for a set of factors in a data frame.

Usage

weighted_factor_sim(des, wts = rep(1, ncol(des))/ncol(des))

Arguments

des

A data frame containing factors for which the weighted similarity matrix will be computed.

wts

A numeric vector of weights corresponding to the factors in the data frame. The default is equal weights for all factors.

Value

A weighted similarity matrix computed for the factors in the data frame.

Examples

# Sample data
des <- data.frame(
  var1 = factor(c("a", "b", "a", "b", "a")),
  var2 = factor(c("c", "c", "d", "d", "d"))
)

# Compute similarity matrix with default equal weights
sim_default_weights <- weighted_factor_sim(des)

# Compute similarity matrix with custom weights
sim_custom_weights <- weighted_factor_sim(des, wts = c(0.7, 0.3))

bbuchsbaum/neighborweights documentation built on April 1, 2024, 8:41 p.m.