Skip to contents

After clustering a set of trajectory data, predict the cluster assignment for new subjects.

Usage

# S3 method for FKM.TPS
predict(object, newdata, ...)

Arguments

object

An object of class FKM.TPS of previously identified clusters.

newdata

A new data frame containing subjects with the same variables previously used for clustering.

...

Additional arguments.

Value

An object of class 'FKM.predicted' containing the following components:

  • predicted_U A data frame containing the subjects with their degree of cluster membership and modal cluster assignment.

  • U The degrees of cluster membership for each subject.

  • Umax The modal class assignment for each subject.

  • wide_data A data frame containing the values that were clustered on.

  • IDmatch A data frame matching the original subject ID variable to a new consecutive subject ID.

  • TPSdata An object of class TPSfit containing the fitted splines for the new subjects.

  • FKM_TPS The inputted object of class FKM.TPS.

  • noise Logical expression indicating whether a noise cluster is included for outliers.

  • k The number of clusters.

  • m The fuzziness parameter.

Examples

library(dplyr); library(tidyr); library(fclust)
data(TS.sim)

fitsplines <- TPSfit(TS.sim, vars=c("Var1", "Var2", "Var3"), time="Time",
     ID="SubjectID", knots_time=c(0, 91, 182, 273, 365), n_fit_times=10)

clusters1 <- cluster.fitted(fitsplines, k=3, m=1.3, seed=12345, RS=5, noise=TRUE)

predicted_clusters <- predict(clusters1, TS.sim.new)
summary(predicted_clusters)
#> Object of type 'FKM.predicted'
#> predict.FKM.TPS(object = clusters1, newdata = TS.sim.new)
#> 
#> Tensor-product splines fit for 30 out of 30 subjects
#> 
#> Degree of membership calculated based on clusters from input 'FKM.TPS' object.
#> 30 subjects clustered into 3 clusters + noise cluster
#> 
#> Clusters based on fitted values at times 0 40.44444 80.88889 121.3333 161.7778 202.2222 242.6667 283.1111 323.5556 364 
#> and slopes between points
#> 
#> Cluster summary for new data:
#>       Cl.size Min.degree Max.degree Mean.degree
#> Clus1       8      0.974      0.996       0.985
#> Clus2      10      0.954      1.000       0.993
#> Clus3      11      0.436      1.000       0.908
#> Noise       1      0.800      0.800       0.800
#> 
#> Output dataset 'predicted_U' contains degree of cluster membership and modal
#>       cluster assignment for each object.
#> Head of dataset 'predicted_U':
#>   Id2 SubjectID        Clus1        Clus2       Clus3        Noise ClusModal
#> 1   1      1626 1.092245e-07 4.488422e-06 0.999995187 2.151411e-07         3
#> 2   2      1627 9.840527e-01 8.237368e-03 0.004473630 3.236267e-03         1
#> 3   3      1629 9.804113e-01 7.494699e-03 0.008777124 3.316871e-03         1
#> 4   4      1634 5.604186e-09 3.366604e-07 0.999999650 7.265761e-09         3
#> 5   5      1641 1.234028e-02 1.118469e-01 0.075447127 8.003657e-01         0
#> 6   6      1650 1.054592e-10 6.247860e-09 0.999999994 1.399693e-10         3
#>