Is there any way to get the standard deviation (R) percentage?

Asked

Viewed 123 times

1

For example..

I have a number of values (prices) related to a product on several different dates.

I need to get the percentage change of that amount.

Currently, prices are giving a standard deviation of 120.00, only I wanted this result in percentage. Type, prices varied by 20% on these specific days.

How to do it in R?

1 answer

2


If you want to know the standard deviation relative to the mean, this is the coefficient of variation. To have in percentage just multiply by a hundred.

Programming the CV in R is a very easy problem to solve.

coefVar <- function(x, na.rm = FALSE){
  sd(x, na.rm = na.rm)/mean(x, na.rm = na.rm)
}

set.seed(9580)    # Torna os resultados reprodutíveis

x <- runif(100, 0, 20)

coefVar(x)
#[1] 0.621354

coefVar(x)*100    # Em porcentagem
#[1] 62.1354

Taking into account the comment on the result of a function calculation, this is what gives me:

y <- c(772.8, 147.28, 993.72)
coefVar(y)*100
#[1] 68.82238

You seem to be right.

  • Um.. I even tried to do this, but the result is getting confusing. For example, only sd gave 336,353. Only when I go to rotate the percentage of the variation it is 63.62789. These 63.62789 is on top of that? Ps.: My knowledge of statistics is very low. If you can explain it to me :)

  • For example, I just did it here. I have these three values, 772.8 / 147.28 / 993.72. With a standard deviation of 439,0409 and a mean of 637,9333, if I divide the sd by the average it gives 0.6882238. Following your logic, I would have to multiply by 100 that would give 68,82%. Because the result using your code is not giving this?

  • Using my code gives you exactly this: [1] 68.82238.

  • I should be doing something wrong. Thanks . :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.