This function determines the final mu vector given the grouping results.
numerical vector. n = length(mu_vec)
is the number of observations.
Presumably it comes from the ADMM algorithm and is not a very good grouping result.
a list, containing the grouping results.
Each element of group_res is a list containing the indecs from the same subgroup.
See RSAVS_S_to_Groups
for the output structure.
a length-3 integer vector, storing `kmin`, `kmax`, `dudahart_kmax` for specifying settings for clustering algorithm.
boolen, whether to use `cluster::pam()` or instead `cluster::clara()` to estimate center of clusters.
a positive integer digit. If group_res
is missing and round_digits
is provided, then the function will directly round the mu_vec
to round_digits
to provide the final grouping results.
a length-n vector of subgroup effects. Observations belonging to the same subgroup should have the same effects.
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.
# 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)
#> alpha_true
#> -1 0 1
#> 36 29 35
# 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))
#>
#> -0.031212280735415
#> 100
# Use `pamk` to determine estiamted group effect
table(RSAVS:::RSAVS_Determine_Mu(alpha_est))
#>
#> -0.93070469388076 -0.00378625575910929 1.0149849134033
#> 37 29 34
# Use directly rounding to determine estimated group effect
table(RSAVS:::RSAVS_Determine_Mu(alpha_est, round_digits = 1))
#>
#> -1.5 -1.4 -1.3 -1.2 -1.1 -1 -0.9 -0.8 -0.7 -0.6 -0.5 -0.3 -0.2 -0.1 0 0.1
#> 2 1 4 5 2 3 8 8 1 1 3 1 3 6 8 4
#> 0.2 0.3 0.4 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.6
#> 3 2 1 1 5 3 6 5 6 3 4 1