0

I am trying to calculate the coefficient of quartile variation in R for every 3 consecutive measurements.

cqv_versatile(
    Q, 
    na.rm = TRUE, 
    digits = 3)
    Q
    49
    44
    34
    33
    37
    48
    20
    48
    37
    42
    44
    35
    40

Does someone knows how to calculate the cqv_versatile with this consecutive interval?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Jacs
  • 1
  • You want to estimate quartiles from 3 data points? Are you sure? – user2974951 Aug 10 '21 at 12:38
  • I want to estimate the (Quartil 3 - Quartil 1)/ (Quartil 3 - Quartil1) for 3 consecutive rows (example: 49,44,34), in order to analyze the material dispersion. My data is non-normal, that is why I choose coefficient of quartile varitions, than i dont need to transformate the data. – Jacs Aug 10 '21 at 12:47
  • I understand, I am asking if you really want to estimate quartiles from three rows? That's a pathetic amount of data, there will be a lot of extrapolation in the estimates. – user2974951 Aug 10 '21 at 12:51
  • I see, in the question did not have the complete data. I have 68 rows for each group of data that I was thinking in apply the coefficient of quartile. – Jacs Aug 10 '21 at 12:55

1 Answers1

0

Here is one way using base R, change the hst variable to your desired sublength (just to be clear, the first coefficient is estimated based on values with indices 1,2,3; the second coefficient is estimated based on values with indices 4,5,6)

Q=as.numeric(read.table(text="49 44 34 33 37 48 20 48 37 42 44 35 40"))

hst=3

sapply(seq(1,length(Q),hst),function(x){
  tmp=x:(pmin(x+hst-1,length(Q)))
  q1=quantile(Q[tmp],0.25)
  q3=quantile(Q[tmp],0.75)
  as.numeric((q3-q1)/(q3+q1))
})

[1] 0.08771930 0.09677419 0.19718310 0.05521472 0.00000000

As mentioned in the comments, you should really use more data to when estimating the coefficient.

If you want to estimate based on a rolling window, so indices 1,2,3 -> 2,3,4 -> ... just replace seq(1,length(Q),hst) with seq(1,length(Q),1).

user2974951
  • 9,535
  • 1
  • 17
  • 24
  • Thank you so much! I will try to see how the estimating coefficient will work in my data, otherwise, I will try another analysis to analyze the dispersion of the material. – Jacs Aug 10 '21 at 13:17
  • @JacquelineSantos If this answered your question consider accepting this answer to close the matter. – user2974951 Aug 13 '21 at 05:28