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

Decostand "frequency" #304

Closed
invertdna opened this issue Jan 18, 2019 · 1 comment
Closed

Decostand "frequency" #304

invertdna opened this issue Jan 18, 2019 · 1 comment
Milestone

Comments

@invertdna
Copy link

invertdna commented Jan 18, 2019

decostand provides the method "frequency" as an option for standardization, and I think the helpfile might be incorrect:

"frequency: divide by margin maximum and multiply by the number of non-zero items, so that the average of non-zero entries is one (Oksanen 1983; default MARGIN = 2)."

But carrying out the operations as described does not yield a mean of one. For example:

a <- sample(0:9, 100, replace = T)  #create some random data; note that it doesn't matter whether these are integers or decimals, etc. 
b <- a/max(a)     #divide by margin max
d <- b*sum(b!=0)   #multiply by number of non-zero items
mean(d[d!=0])   #take mean of non-zero items

yields an integer between about 45 and 55, depending on the sampling.

By contrast,

f <- decostand(a, method = "frequency") 
mean(f[f!=0])

does have the intended effect of making the mean of non-zero numbers equal to zero.

The code for decostand has the following:

frequency = {
        if (missing(MARGIN)) MARGIN <- 2
        tmp <- pmax(k, apply(x, MARGIN, sum, na.rm = na.rm))
        fre <- apply(x > 0, MARGIN, sum, na.rm = na.rm)
        tmp <- fre/tmp
        x <- sweep(x, MARGIN, tmp, "*")
    }

Which essentially divides the number of non-zero entries by the vector SUM, and then multiplies the vector by that dividend.

In sum, I think the helpfile wrongly describes the operation performed.

@jarioksa
Copy link
Contributor

Corrected in commit 6617fca. Thanks.

@jarioksa jarioksa added this to the 2.5-4 milestone Jan 27, 2019
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

2 participants