Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot directly skip rearrange in autoplot #166

Open
jmbarbone opened this issue Dec 13, 2022 · 0 comments
Open

Cannot directly skip rearrange in autoplot #166

jmbarbone opened this issue Dec 13, 2022 · 0 comments

Comments

@jmbarbone
Copy link

The problem

I have a correlation matrix with a lot of missing values. This causes the backend rearranging to fail when it tries to change the order. However, there's direct way of preventing the reordering attempt, which I would like to do. Using method = "Identity" still checks if the object is valid for seriation.

Reproducible example

library(corrr)
x <- matrix(1:20, nrow = 5)
x[seq(1, 20, 2)] <- NA
x <- as.data.frame(x)
x <- correlate(x)
#> Correlation computed with
#> • Method: 'pearson'
#> • Missing treated using: 'pairwise.complete.obs'
x
#> # A tibble: 4 × 5
#>   term     V1    V2    V3    V4
#>   <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 V1       NA    NA     1    NA
#> 2 V2       NA    NA    NA     1
#> 3 V3        1    NA    NA    NA
#> 4 V4       NA     1    NA    NA
try(autoplot(x))
#> Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'
try(autoplot(x, method = "Identity"))
#> Error in seriate.dist(dist(m), method = method) : 
#>   NAs not allowed in distance matrix x!
try(rearrange(x))
#> Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'
try(rearrange(x, method = "Identity"))
#> Error in seriate.dist(dist(m), method = method) : 
#>   NAs not allowed in distance matrix x!

class(x) <- c("foo", class(x))

rearrange.foo <- function(x, method = NA, absolute = TRUE) {
  if (is.na(method)) {
    return(x)
  }
  
  NextMethod()
}

try(rearrange(x, method = NA))
#> # A tibble: 4 × 5
#>   term     V1    V2    V3    V4
#>   <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 V1       NA    NA     1    NA
#> 2 V2       NA    NA    NA     1
#> 3 V3        1    NA    NA    NA
#> 4 V4       NA     1    NA    NA
try(autoplot(x, method = NA))

Created on 2022-12-13 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant