https://github.com/krlmlr/mangow
Generate a Manhattan Distance problem from a Gower's distance problem
https://github.com/krlmlr/mangow
Last synced: about 2 months ago
JSON representation
Generate a Manhattan Distance problem from a Gower's distance problem
- Host: GitHub
- URL: https://github.com/krlmlr/mangow
- Owner: krlmlr
- Created: 2015-01-19T11:00:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-01-01T12:29:10.000Z (over 5 years ago)
- Last Synced: 2025-02-12T20:45:03.961Z (3 months ago)
- Language: R
- Homepage: http://krlmlr.github.io/mangow
- Size: 165 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)pkgload::load_all()
```# mangow
[](https://travis-ci.org/krlmlr/mangow)
[](https://codecov.io/github/krlmlr/mangow?branch=master)
[](https://www.tidyverse.org/lifecycle/#stable)
[](https://CRAN.R-project.org/package=mangow)The goal of mangow is to normalize provide a transformation from Gower to Manhattan distance.
The only exported function in this package converts a data frame to an equivalent matrix where the pairwise Gower distances in the input data frame are identical to the pairwise Manhattan distances in the resulting matrix.
With this transformation, efficient algorithms for the Manhattan distance, such as nearest-neighbor for L1, can be extended to work with Gower distances.## Installation
You can install the released version of mangow from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("mangow")
```And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("krlmlr/mangow")
```## Example
This basic example computes a Gower dissimilarity matrix on a subset of the Iris data and compares it with the L1 dissimilarity matrix of the transformed data.
```{r read}
iris_sub <- iris[c(1:2, 50:51, 100:101), ]
row.names(iris_sub) <- NULL
iris_subcluster::daisy(iris_sub, metric = "gower")
```The transformation returns a matrix with the same number of rows, but potentially more columns, depending on the data types of the input columns.
```{r transform}
library(mangow)mangow_iris_sub <- mangow(iris_sub)
mangow_iris_sub
```The resulting dissimilarity matrix for the Manhattan metric is the same as the Gower dissimilarity matrix on the input.
```{r daisy}
cluster::daisy(mangow_iris_sub, metric = "manhattan")
```