# ISMtools <img src="man/figures/logo.png" align="right" height="139" />

## Overview

**ISMtools** is a comprehensive R package for Interpretive Structural Modelling (ISM) analysis. ISM is a methodology for identifying and summarizing relationships among specific elements which define an issue or problem.

The package provides:

- **Matrix operations**: Create adjacency matrices, convert edge lists, and compute reachability matrices
- **Structured input support**: Build adjacency matrices from SSIM (Structural Self-Interaction Matrix)
- **Level partitioning**: Hierarchical decomposition of system elements
- **MICMAC analysis**: Driving power and dependence analysis for factor classification
- **Visualization**: Both static and interactive ISM structure diagrams

## Installation

### From CRAN (once available)

```r
install.packages("ISMtools")
```


## Quick Start

```r
library(ISMtools)

# Create an adjacency matrix
adj_matrix <- matrix(c(
  0, 1, 0, 0, 0,
  0, 0, 1, 0, 0,
  0, 0, 0, 1, 1,
  0, 0, 0, 0, 0,
  0, 0, 0, 0, 0
), nrow = 5, byrow = TRUE)

# Compute reachability matrix
reach_matrix <- compute_reachability(adj_matrix)

# Perform level partitioning
levels <- level_partitioning(reach_matrix)
print(levels)

# Visualize the ISM structure
plot_ism(reach_matrix)

# Optional interactive visualization
if (requireNamespace("visNetwork", quietly = TRUE)) {
  plot_interactive_ism(reach_matrix)
}
```

## Main Functions

| Function | Description |
|----------|-------------|
| `create_relation_matrix()` | Create or convert adjacency matrices |
| `convert_to_matrix()` | Convert edge lists to adjacency matrices |
| `compute_reachability()` | Calculate reachability matrix using Warshall's algorithm |
| `level_partitioning()` | Perform hierarchical level decomposition |
| `plot_ism()` | Static ISM structure visualization |
| `plot_interactive_ism()` | Interactive ISM visualization with drag-and-drop |

## Example: Converting Edge List to Matrix

```r
# From data frame
edge_df <- data.frame(
  source = c("A", "A", "B", "C"),
  target = c("B", "C", "D", "D")
)
adj_matrix <- convert_to_matrix(edge_df, from = "source", to = "target")

# From matrix edge list
edge_mat <- matrix(c("A", "B", "B", "C", "C", "D"), ncol = 2, byrow = TRUE)
adj_matrix <- convert_to_matrix(edge_mat)
```

## Citation

If you use ISMtools in your research, please cite:

```
Tang Y (2026). ISMtools: Interpretive Structural Modelling Analysis Tools.

```

## References

- Warfield, J. N. (1974). Developing interconnection matrices in structural modeling. *IEEE Transactions on Systems, Man, and Cybernetics*, SMC-4(1), 81-87. doi:10.1109/TSMC.1974.5408524

## License
MIT. See `LICENSE`.