Skip to contents

A method for printing objects of class clustglmm, the outputs of clustGLMM.

Usage

# S3 method for class 'clustglmm'
print(x, which = "call", ...)

Arguments

x

an object of class "clustglmm", an output of clustGLMM function.

which

a vector containing the following strings

"call"

to print the overview of the estimated model,

"clustering"

to print the brief summary of the clustering.

...

other arguments.

Details

First, if "call" is in which, it prints x$call that summarizes what has been fitted including sample sizes, number of units, observations per unit, chosen maximal number of clusters, overview of outcomes and selected types, fixed-effects common to all groups, random-effects with the structure of Sigma matrix, group-specific formulae for outcomes, list of other group-specific parameters and summary of the MCMC sampling.

Next, if "clustering" is in which, it summarizes the clustering based on sampled indicators U for each chain separately. First, modeGplus, the most frequent value of Gplus - number of non-empty components, is determined. Then, all samples of cluster indicators U are gathered from all units to determine modeGplus most frequent cluster labels, stored in clusters. To each unit i we assign the cluster label from clusters that maximizes the frequency of samples of U[i], stored in clustering. We also keep the relative frequency to the assigned cluster, stored in certainty. By choosing reasonable threshold, e.g. 0.5, you can make a unit unclassified (0) if the certainty is not high enough: clustering[certainty < threshold] <- 0. If G = 1, then clustering summary is irrelevant.

Value

No returned value, only prints.

References

Vávra, J., Komárek, A., Grün, B., Malsiner-Walli, G. Clusterwise multivariate regression of mixed-type panel data. Stat Comput 34, 46 (2024). https://doi.org/10.1007/s11222-023-10304-5

Author

Jan Vávra

See also

Examples


### Get some longitudinal mixed type data
### here generated by generate_longitudinal_mixed_type_data()
data("longitudinal_mixed_type_data")

# Examples here demonstrate the basic use of the available functions on a toy dataset.
# For more thorough analyses see the vignettes.


###-----------------------------------------------------------------------------
###     Prepare inputs for clustGLMM()
###-----------------------------------------------------------------------------
id <- "i"

family <- c("num", "poi", "bin", "ord", "cat")
names(family) <- Ys <- c("ynum", "ypoi", "ybin", "yord", "ycat")

## Create list of formulae for each outcome
formula <- list()
for(y in Ys){
  formula[[y]] <- list()
  formula[[y]]$fixed <- ~ f
  formula[[y]]$group <- ~ x
  formula[[y]]$random <- ~ 1
  formula[[y]]$offset <- ""
}
formula
#> $ynum
#> $ynum$fixed
#> ~f
#> <environment: 0x559aee566438>
#> 
#> $ynum$group
#> ~x
#> <environment: 0x559aee566438>
#> 
#> $ynum$random
#> ~1
#> <environment: 0x559aee566438>
#> 
#> $ynum$offset
#> [1] ""
#> 
#> 
#> $ypoi
#> $ypoi$fixed
#> ~f
#> <environment: 0x559aee566438>
#> 
#> $ypoi$group
#> ~x
#> <environment: 0x559aee566438>
#> 
#> $ypoi$random
#> ~1
#> <environment: 0x559aee566438>
#> 
#> $ypoi$offset
#> [1] ""
#> 
#> 
#> $ybin
#> $ybin$fixed
#> ~f
#> <environment: 0x559aee566438>
#> 
#> $ybin$group
#> ~x
#> <environment: 0x559aee566438>
#> 
#> $ybin$random
#> ~1
#> <environment: 0x559aee566438>
#> 
#> $ybin$offset
#> [1] ""
#> 
#> 
#> $yord
#> $yord$fixed
#> ~f
#> <environment: 0x559aee566438>
#> 
#> $yord$group
#> ~x
#> <environment: 0x559aee566438>
#> 
#> $yord$random
#> ~1
#> <environment: 0x559aee566438>
#> 
#> $yord$offset
#> [1] ""
#> 
#> 
#> $ycat
#> $ycat$fixed
#> ~f
#> <environment: 0x559aee566438>
#> 
#> $ycat$group
#> ~x
#> <environment: 0x559aee566438>
#> 
#> $ycat$random
#> ~1
#> <environment: 0x559aee566438>
#> 
#> $ycat$offset
#> [1] ""
#> 
#> 
# intercept term will be group-specific 
# since it appears in $group which has a preference over $fixed

## All other inputs need to be prepared,
## unless the default values are desired (varying, save, howsave, param, tuning).
## See the vignette for how these can be adjusted.

###-----------------------------------------------------------------------------
###     Calling clustGLMM()
###-----------------------------------------------------------------------------

Gmax <- 5     # maximal number of mixture components to be considered
nchains <- 2  # number of chains to be sampled 

## No inits specified
set.seed(123456789)
mcmc <- clustGLMM(formula = formula, id = id, family = family, 
                  data = longitudinal_mixed_type_data, 
                  G = Gmax, iter = 100, nchains = nchains)
#> Inits are missing, calculating...
#> Inits are ready.
#> Settings ready, about to start for ch in 1:nchains.
#> Inits for chain 1 are ready.
#> Triggering C function.
#> 
#> Chain: 1, (1 %)
Chain: 1, (2 %)
Chain: 1, (3 %)
Chain: 1, (4 %)
Chain: 1, (5 %)
Chain: 1, (6 %)
Chain: 1, (7 %)
Chain: 1, (8 %)
Chain: 1, (9 %)
Chain: 1, (10 %)
Chain: 1, (11 %)
Chain: 1, (12 %)
Chain: 1, (13 %)
Chain: 1, (14 %)
Chain: 1, (15 %)
Chain: 1, (16 %)
Chain: 1, (17 %)
Chain: 1, (18 %)
Chain: 1, (19 %)
Chain: 1, (20 %)
Chain: 1, (21 %)
Chain: 1, (22 %)
Chain: 1, (23 %)
Chain: 1, (24 %)
Chain: 1, (25 %)
Chain: 1, (26 %)
Chain: 1, (27 %)
Chain: 1, (28 %)
Chain: 1, (29 %)
Chain: 1, (30 %)
Chain: 1, (31 %)
Chain: 1, (32 %)
Chain: 1, (33 %)
Chain: 1, (34 %)
Chain: 1, (35 %)
Chain: 1, (36 %)
Chain: 1, (37 %)
Chain: 1, (38 %)
Chain: 1, (39 %)
Chain: 1, (40 %)
Chain: 1, (41 %)
Chain: 1, (42 %)
Chain: 1, (43 %)
Chain: 1, (44 %)
Chain: 1, (45 %)
Chain: 1, (46 %)
Chain: 1, (47 %)
Chain: 1, (48 %)
Chain: 1, (49 %)
Chain: 1, (50 %)
Chain: 1, (51 %)
Chain: 1, (52 %)
Chain: 1, (53 %)
Chain: 1, (54 %)
Chain: 1, (55 %)
Chain: 1, (56 %)
Chain: 1, (57 %)
Chain: 1, (58 %)
Chain: 1, (59 %)
Chain: 1, (60 %)
Chain: 1, (61 %)
Chain: 1, (62 %)
Chain: 1, (63 %)
Chain: 1, (64 %)
Chain: 1, (65 %)
Chain: 1, (66 %)
Chain: 1, (67 %)
Chain: 1, (68 %)
Chain: 1, (69 %)
Chain: 1, (70 %)
Chain: 1, (71 %)
Chain: 1, (72 %)
Chain: 1, (73 %)
Chain: 1, (74 %)
Chain: 1, (75 %)
Chain: 1, (76 %)
Chain: 1, (77 %)
Chain: 1, (78 %)
Chain: 1, (79 %)
Chain: 1, (80 %)
Chain: 1, (81 %)
Chain: 1, (82 %)
Chain: 1, (83 %)
Chain: 1, (84 %)
Chain: 1, (85 %)
Chain: 1, (86 %)
Chain: 1, (87 %)
Chain: 1, (88 %)
Chain: 1, (89 %)
Chain: 1, (90 %)
Chain: 1, (91 %)
Chain: 1, (92 %)
Chain: 1, (93 %)
Chain: 1, (94 %)
Chain: 1, (95 %)
Chain: 1, (96 %)
Chain: 1, (97 %)
Chain: 1, (98 %)
Chain: 1, (99 %)
Chain: 1, (100 %)

#> Sampling of chain 1 is completed.
#> Saving the last state of chain 1 is completed.
#> Saving chain 1 is completed.
#> Inits for chain 2 are ready.
#> Triggering C function.
#> 
#> Chain: 2, (1 %)
Chain: 2, (2 %)
Chain: 2, (3 %)
Chain: 2, (4 %)
Chain: 2, (5 %)
Chain: 2, (6 %)
Chain: 2, (7 %)
Chain: 2, (8 %)
Chain: 2, (9 %)
Chain: 2, (10 %)
Chain: 2, (11 %)
Chain: 2, (12 %)
Chain: 2, (13 %)
Chain: 2, (14 %)
Chain: 2, (15 %)
Chain: 2, (16 %)
Chain: 2, (17 %)
Chain: 2, (18 %)
Chain: 2, (19 %)
Chain: 2, (20 %)
Chain: 2, (21 %)
Chain: 2, (22 %)
Chain: 2, (23 %)
Chain: 2, (24 %)
Chain: 2, (25 %)
Chain: 2, (26 %)
Chain: 2, (27 %)
Chain: 2, (28 %)
Chain: 2, (29 %)
Chain: 2, (30 %)
Chain: 2, (31 %)
Chain: 2, (32 %)
Chain: 2, (33 %)
Chain: 2, (34 %)
Chain: 2, (35 %)
Chain: 2, (36 %)
Chain: 2, (37 %)
Chain: 2, (38 %)
Chain: 2, (39 %)
Chain: 2, (40 %)
Chain: 2, (41 %)
Chain: 2, (42 %)
Chain: 2, (43 %)
Chain: 2, (44 %)
Chain: 2, (45 %)
Chain: 2, (46 %)
Chain: 2, (47 %)
Chain: 2, (48 %)
Chain: 2, (49 %)
Chain: 2, (50 %)
Chain: 2, (51 %)
Chain: 2, (52 %)
Chain: 2, (53 %)
Chain: 2, (54 %)
Chain: 2, (55 %)
Chain: 2, (56 %)
Chain: 2, (57 %)
Chain: 2, (58 %)
Chain: 2, (59 %)
Chain: 2, (60 %)
Chain: 2, (61 %)
Chain: 2, (62 %)
Chain: 2, (63 %)
Chain: 2, (64 %)
Chain: 2, (65 %)
Chain: 2, (66 %)
Chain: 2, (67 %)
Chain: 2, (68 %)
Chain: 2, (69 %)
Chain: 2, (70 %)
Chain: 2, (71 %)
Chain: 2, (72 %)
Chain: 2, (73 %)
Chain: 2, (74 %)
Chain: 2, (75 %)
Chain: 2, (76 %)
Chain: 2, (77 %)
Chain: 2, (78 %)
Chain: 2, (79 %)
Chain: 2, (80 %)
Chain: 2, (81 %)
Chain: 2, (82 %)
Chain: 2, (83 %)
Chain: 2, (84 %)
Chain: 2, (85 %)
Chain: 2, (86 %)
Chain: 2, (87 %)
Chain: 2, (88 %)
Chain: 2, (89 %)
Chain: 2, (90 %)
Chain: 2, (91 %)
Chain: 2, (92 %)
Chain: 2, (93 %)
Chain: 2, (94 %)
Chain: 2, (95 %)
Chain: 2, (96 %)
Chain: 2, (97 %)
Chain: 2, (98 %)
Chain: 2, (99 %)
Chain: 2, (100 %)

#> Sampling of chain 2 is completed.
#> Saving the last state of chain 2 is completed.
#> Saving chain 2 is completed.
#> All chains have been sampled.
                       
###-----------------------------------------------------------------------------
###     Printing the results
###-----------------------------------------------------------------------------

mcmc
#> ###------------------------------------------------------------###
#> ### Model Based Clustering for Generalized Linear Mixed Models ###
#> ###------------------------------------------------------------###
#> N = sample size: 400
#> n = number of units: 100
#> observations per unit (min | median | max): 4 | 4 | 4 
#> G = maximal number of components: 5
#> 
#> Overview of outcomes: 
#> num: ynum
#> poi: ypoi
#> bin: ybin
#> ord: yord
#> cat: ycat
#> 
#> Fixed effects invariant towards clustering (in order of appearance): 
#> ynum ~ f
#> ypoi ~ f
#> ybin ~ f
#> yord ~ f
#> ycat ~ f
#> 
#> Random effects invariant towards clustering: 
#> ynum ~ 1
#> ypoi ~ 1
#> ybin ~ 1
#> yord ~ 1
#> ycat ~ 1
#> 
#> The structure of covariance matrix Sigma for random effects: 
#> ynum_(Intercept)
#> ypoi_(Intercept)
#> ybin_(Intercept)
#> yord_(Intercept)
#> ycat_(Intercept)
#> 
#> Group-specific effects for outcomes (in order of appearance): 
#> ynum ~ x
#> ypoi ~ x
#> ybin ~ x
#> yord ~ x
#> ycat ~ x
#> 
#> Other group-specific parameters: prec_num, sd_num, var_num, c_ord, a_ord, pi_ord
#> 
#> MCMC sampling: 
#> nchains = number of sampled chains: 2
#> iter = length of the chain: 100
#> Overall acceptance: 36.42% 
#> Initialized by a random partition.
print(mcmc, which = "clustering")
#> ## Clustering based on sampled indicators:
#> -----------------------------------------------------------------------
#> Chain 1
#> -----------------------------------------------------------------------
#> The most-frequent number of non-empty components: 2
#> Empty components: 1, 4, 5
#> Non-empty components: 2, 3
#>  2  3 
#> 52 48 
#> Average certainty of assignment to a component: 
#>         2         3 
#> 0.9684615 0.9710417 
#> -----------------------------------------------------------------------
#> Chain 2
#> -----------------------------------------------------------------------
#> The most-frequent number of non-empty components: 3
#> Empty components: 3, 4
#> Non-empty components: 1, 2, 5
#>  1  2  5 
#> 12 51 37 
#> Average certainty of assignment to a component: 
#>         1         2         5 
#> 0.7141667 0.9488235 0.7713514 
print(mcmc, which = c("call", "clustering"))
#> ###------------------------------------------------------------###
#> ### Model Based Clustering for Generalized Linear Mixed Models ###
#> ###------------------------------------------------------------###
#> N = sample size: 400
#> n = number of units: 100
#> observations per unit (min | median | max): 4 | 4 | 4 
#> G = maximal number of components: 5
#> 
#> Overview of outcomes: 
#> num: ynum
#> poi: ypoi
#> bin: ybin
#> ord: yord
#> cat: ycat
#> 
#> Fixed effects invariant towards clustering (in order of appearance): 
#> ynum ~ f
#> ypoi ~ f
#> ybin ~ f
#> yord ~ f
#> ycat ~ f
#> 
#> Random effects invariant towards clustering: 
#> ynum ~ 1
#> ypoi ~ 1
#> ybin ~ 1
#> yord ~ 1
#> ycat ~ 1
#> 
#> The structure of covariance matrix Sigma for random effects: 
#> ynum_(Intercept)
#> ypoi_(Intercept)
#> ybin_(Intercept)
#> yord_(Intercept)
#> ycat_(Intercept)
#> 
#> Group-specific effects for outcomes (in order of appearance): 
#> ynum ~ x
#> ypoi ~ x
#> ybin ~ x
#> yord ~ x
#> ycat ~ x
#> 
#> Other group-specific parameters: prec_num, sd_num, var_num, c_ord, a_ord, pi_ord
#> 
#> MCMC sampling: 
#> nchains = number of sampled chains: 2
#> iter = length of the chain: 100
#> Overall acceptance: 36.42% 
#> Initialized by a random partition.
#> 
#> ## Clustering based on sampled indicators:
#> -----------------------------------------------------------------------
#> Chain 1
#> -----------------------------------------------------------------------
#> The most-frequent number of non-empty components: 2
#> Empty components: 1, 4, 5
#> Non-empty components: 2, 3
#>  2  3 
#> 52 48 
#> Average certainty of assignment to a component: 
#>         2         3 
#> 0.9684615 0.9710417 
#> -----------------------------------------------------------------------
#> Chain 2
#> -----------------------------------------------------------------------
#> The most-frequent number of non-empty components: 3
#> Empty components: 3, 4
#> Non-empty components: 1, 2, 5
#>  1  2  5 
#> 12 51 37 
#> Average certainty of assignment to a component: 
#>         1         2         5 
#> 0.7141667 0.9488235 0.7713514