View source: R/pre_define_functions.r
RSAVS_Determine_Mu | R Documentation |
This function determines the final mu vector given the grouping results.
RSAVS_Determine_Mu(
mu_vec,
group_res,
klim = c(2, 7, 4),
usepam = (length(mu_vec) < 2000),
round_digits = NULL
)
mu_vec |
numerical vector. |
group_res |
a list, containing the grouping results.
Each element of group_res is a list containing the indecs from the same subgroup.
See |
klim |
a length-3 integer vector, storing 'kmin', 'kmax', 'dudahart_kmax' for specifying settings for clustering algorithm. |
usepam |
boolen, whether to use 'cluster::pam()' or instead 'cluster::clara()' to estimate center of clusters. |
round_digits |
a positive integer digit. If |
Currently, the resulting subgroup effects are the average value of mu_vec
for those belonging to the same subgroup according to group_res
.
If group_res
is missing and round_digits
is NULL
,
then a simple K-means is performed on mu_vec
to get the estimated grouping result.
a length-n vector of subgroup effects. Observations belonging to the same subgroup should have the same effects.
# basic settings
set.seed(1024)
n <- 100 # number of observations
group_center <- c(-1, 0, 1) # three group centers
# subgroup effect vector
alpha_true <- sample(group_center, size = n, replace = TRUE)
alpha_est <- alpha_true + rnorm(n, sd = 0.25) # add noise to group effect
table(alpha_true)
# Use `group_res` to determine estimated group effect from `alpha_est`
d_mat <- RSAVS:::RSAVS_Generate_D_Matrix(n) # pair-wise difference matrix
# Normally, s_vec should come from the algorithm
# Here we just use a simple estimate, which might lead to not so satisfing results
s_vec <- round(d_mat %*% alpha_est, 0)
group_res <- RSAVS:::RSAVS_S_to_Groups(s_vec, n)
table(RSAVS:::RSAVS_Determine_Mu(alpha_est, group_res = group_res))
# Use `pamk` to determine estiamted group effect
table(RSAVS:::RSAVS_Determine_Mu(alpha_est))
# Use directly rounding to determine estimated group effect
table(RSAVS:::RSAVS_Determine_Mu(alpha_est, round_digits = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.