Statistics

Descriptive statistics

The statistics module computes summary statistics of dataframe variables (see the documentation in st.pdf ). We only consider statistics of finite populations taken in their entirety.

Second task

We can now find a new solution to Rosetta Code’s second task.

First read the two CSV data files (patients.csv and visits.csv).

make "patients (csv.read "patients.csv [char char])
make "visits (csv.read "visits.csv [char char num])

and print the two dataframes:

df.print :patients 
  PATIENT_ID     LASTNAME
      <char>       <char>
     1001.00       Hopper
     4004.00        Wirth
     3003.00       Kemeny
     2002.00      Gosling
     5005.00        Kurtz
df.print :visits 
  PATIENT_ID   VISIT_DATE        SCORE
      <char>       <char>        <num>
     2002.00   2020-09-10         6.80
     1001.00   2020-09-17         5.50
     4004.00   2020-09-24         8.40
     2002.00   2020-10-08      missing
     1001.00      missing         6.60
     3003.00   2020-11-12      missing
     4004.00   2020-11-05         7.00
     1001.00   2020-11-19         5.30 

Then create two dataframes containing summary stastistics.

make "sum_mean df.select.variables (st.summary :visits "SCORE  [PATIENT_ID]) [PATIENT_ID sum mean]
make "maxdate df.select.variables (st.min.max :visits "VISIT_DATE [PATIENT_ID] [char] "true) [PATIENT_ID max_date]

For example, “sum_mean” includes the total and mean score per patient, dropping missing observations.

[[num num num] [[PATIENT_ID 4004 1001 2002] [sum 15.4 17.4 6.8] [mean 7.7 5.8 6.8]]]

Finally, the dataframes are joined in a single sorted output.

make "out df.left.join :patients :sum_mean [PATIENT_ID] [PATIENT_ID]
make "out df.left.join :out :maxdate [PATIENT_ID] [PATIENT_ID]
make "out df.sort :out [PATIENT_ID]
df.print :out 
  PATIENT_ID     LASTNAME          sum         mean     max_date
      <char>       <char>        <num>        <num>       <char>
     1001.00       Hopper        17.40         5.80   2020-11-19
     2002.00      Gosling         6.80         6.80   2020-10-08
     3003.00       Kemeny      missing      missing   2020-11-12
     4004.00        Wirth        15.40         7.70   2020-11-05
     5005.00        Kurtz      missing      missing      missing