0
$\begingroup$

I'm working on an R package which does an automatic description of datasets (here if you ever want to check it out).

For now, the default behavior of the package is to describe any numeric variable with basic statistics, i.e minimum, maximum, median, IQR, mean, and standard deviation.

I would like to extend this behavior to dates as well. All those calculations can be performed for dates with no problem of interpretation, except for the standard deviation.

Here is an example:

my_date = structure(17897:17921, class = "Date") #in R, this creates a vector of all dates from 2019-01-01 to 2019-01-25

cross_summary(my_date) #a function from my package, rarely used on its own but OK for the example
#> Min / Max 
#> "2019-01-01 / 2019-01-25" 
#> Med [IQR] 
#> "2019-01-13 [2019-01-07;2019-01-19]" 
#> Mean (std) 
#> "2019-01-13 (7.4)" 
#> N (NA) 
#> "25 (0)" 

Here, the standard deviation is expressed in days which can be surprising, or at least hard to interpret. Moreover, R has other date formats such as POSIXct, for which the standard deviation would be expressed in seconds. I'm planning to add the unit after the standard deviation but I'm afraid this will not be enough.

However, I still find it important to have a measure of dispersion, in addition of IQR, as this latter has to round somehow in case of ties.

Is there a better measure of the dispersion of dates other than std and IQR? If not, how can I help my user interpret these beyond displaying the unit?

$\endgroup$
-1
$\begingroup$

Are you familiar with levels of measurement? Dates are ordinal, so you can compare them (<, >, =), but cannot do mathematical operations on them, so calculating mean, standard deviation, or similar metrics doesn't make sense for dates. You can calculate minimum, maximum, median, quantiles, etc. because they need only sorting. To measure dispersion you can use things like range (max - min), or IQR.

You could calculate mean and similar statistics for the count of days, so if someone wants to have such statistics, they can always transform dates to the days since some date.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Daily dates are equally spaced (setting aside minute astronomical considerations). I see no objection in principle to mean and standard deviation. The mean date of 26 June, 27 June and 28 June is ... 27 June. Clearly you have to convert to integers first, and convert back, except for trivial examples. Also, the mean of integers doesn't have to be an integer, but this is no more troubling than non-integer mean number of children or cats or cars across households. In view of this, your second sentence looks too strong for me. (Let's underline that daily dates are only one kind of date.) $\endgroup$ – Nick Cox Jun 28 at 14:33
  • $\begingroup$ @NickCox technically yes, but this would be rather confusing. That’s why I’ve written the second paragraph: if you convert dates to “days since” it makes sense. $\endgroup$ – Tim Jun 28 at 14:45
  • $\begingroup$ I don't see what needs to be confusing. Anyone capable of understanding standard deviation can understand the mapping between conventional date and counts since some origin. Many people understand different calendars in any case. (In some fields it's also customary to work with day of year counted from 1 for 1 January to 365 or 366.) $\endgroup$ – Nick Cox Jun 28 at 14:53
  • $\begingroup$ I second @Nick on this, I don't think that dates should be treated as ordinal. For instance, if I record the date of departure for holidays, I would feel right to plot the density or calculate a confidence interval if there is only one peak (unlikely). I think that converting to "days since" would make little sense in this case. Also, this would require a time origin, which is not often known or relevant. $\endgroup$ – Dan Chaltiel Jun 28 at 14:53
  • $\begingroup$ It's not especially odd either that the standard deviation of dates is not a date. The SD of temperature or mass is not a temperature or mass either: it just has the same units of measurement. $\endgroup$ – Nick Cox Jun 29 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.