Skip to content

Randomise pairwise elements of a matrix #24

@SamPaplauskas

Description

@SamPaplauskas

Title

Randomise pairwise elements of a matrix

Issue description

I have a matrix of values which are a table of differences.

I want to compare these obs values to a randomly generated null values.

This tests whether my obs values are significant, rather than occur by chance.

I want to keep the identity of the values...and randomise the pairwise comparisons which produced them.

What I have tried

sample function
but I am worried that this creates a non-sensical set of null values

Reproduce the problem

create matrix which shows pairwise differences, like my obs data matrix

m.obs <- matrix(round(runif(10), digits = 2), ncol=16, nrow=16)
m.obs[lower.tri(m.obs)] <- m.obs[upper.tri(m.obs)]
diag(m.obs) <- NA

this m is the same as

m.obs[upper.tri(m.obs)] <- NA

Desired outcome

x <- 1:16

m.null <- m.obs

x.perm <- sample(x, replace = FALSE)

rownames(m.null) <- x.perm
colnames(m.null) <- x.perm

m.null

I want this but where the values are then sorted by the randomised row and colnames
...and I did not accomplish this by already trying sort and order functions

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions