Package: change_detection
Change detection in prescribing dataDetects changes in time series with a python wrapper around the R package gets (https://cran.r-project.org/web/packages/gets/index.html). Uses a combination of Google BigQuery and Python to query data, which is then fed to the R change detection code. Outputs a table containing results.Installationpip install change_detectionAnaconda users may have toconda install rpy2andconda install geopandasif not already installed.UsageSeehttps://github.com/ebmdatalab/change_detection/blob/master/examples/examples.ipynbfor examples of use.Data flowGet data, by:using a csv indata/<name>, which must have only the fieldscode,month,numeratoranddenominatorcreating a BigQuery SQL query in the same folder as the notebook that you're using, query must produce a table with only the fieldscode,month,numeratoranddenominatorquerying any number of the OpenPrescribing measures in BigQueryReshapes data with PandasSplits data into chunks and passes each chunk to the R change detection codeThe resulting output is then extracted with further R codeThe R outputs are then concatenatedOptionsnamespecifies either the name of the custom SQL file, or the name of the BigQuery measure to be queriedverbosemakes the R output more verbose to help with bug fixingdefault = Falsesamplefor testing purposes, takes a random sample of 100 entities, to reduce processing timedefault = Falsemeasurespecifies that thenamespecified refers to a measure, rather than custom SQLdefault = Falsedirectionspecifies which direction to look for changes, may be'up','down', or'both',default = 'both'use_cachepasses theuse_cacheoption tobq.cached_readdefault = Truecsv_nameto specify a .csv file to be used in the change detection, rather than getting the data from BigQueryoverwriteforces reprocessing of the change detection, default behaviour is to not re-run if the output files existdefault = Falsedraw_figuresdraw an R plot for each of the time-series, along with plotting regression lines/breaks. These are stored in thefiguresfolder. Options are'no'or'yes'default = 'no'Output tableTiming Measuresis.tfirstFirst negative breakis.tfirst.pknownFirst negative break after a known intervention dateis.tfirst.pknown.offsFirst negative break after a known intervention date not offset by a XX% increaseis.tfirst.offsFirst negative break not offset by a XX% increaseis.tfirst.bigSteepest break as identified byis.slope.maSlope Measuresis.slope.maAverage slope over steepest segment contributing at least XX% of total dropis.slope.ma.propAverage slope as proportion to prior levelis.slope.ma.prop.levPercentage of the total drop the segment used to evaluate the slope makes upLevel Measuresis.intlev.initlevPre-drop levelis.intlev.finallevEnd levelis.intlev.levdDifference between pre and end levelis.intlev.levdpropProportion of dropRequirementsPython with an associated install of R. Python dependencies should be dealt with on installation (though for my install, I had to install rpy2 separately. R packages should be installed with the package is first loaded.Python installation requires:ebmdatalab libraryhttps://github.com/ebmdatalab/datalab-pandasrpy2 (to install R and the below libraries)pandaspandas-gbqnumpyR installation requires:zoocaToolsgets