---
title: "funIHC: Functional Iterative Hierarchical Clustering"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{funIHC: Functional Iterative Hierarchical Clustering}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```
## Overview

The funIHC package implements the functional iterative hierarchical clustering method from the paper Higgins, C., Carey, M. Addressing class imbalance in functional data clustering. Adv Data Anal Classif (2024). https://doi.org/10.1007/s11634-024-00611-8

## Distance Metrics
As described in our paper, we propose three distinct distance metrics for use with funIHC:

1. funIHC (curves): where the functional form of the curves is directly utilized with a measure of functional distance to quantify dissimilarity between them. Set type=0

2. funIHC (1st derivative): the first-order derivative of the curves is utilized with a measure of functional distance to quantify dissimilarity between them. Set type=1

3. funIHC (coefficients): which involves a dimension reduction via a basis function expansion of the original curves followed by computation of distances based on the resulting vectors. Set type=2

## Example
An example demonstrating how to use funIHC, along with the data required to reproduce simulations described in our paper, is provided.


```{r setup}
library(funIHC)

rds_path <- system.file("extdata", "U1505.rds", package = "funIHC")
example_data <- readRDS(rds_path) #Data from Table 2 in the paper, with M=15 and sigma = 0.05 

Data <- example_data$Data
Data = t(Data)
x = 1:15 #Number of time points (M=15 or 200 in the simulations)

res = funIHC(x,Data,type=0) #Run funIHC, type refers to the choice of distance metric: curves (0), first derivative (1) or coefficients (2)

table(res$label)


```
