Skip to content

Commit

Permalink
Merge pull request #292 from OHDSI/new_release_cran
Browse files Browse the repository at this point in the history
Update DESCRIPTION
  • Loading branch information
xihang-chen authored Nov 29, 2024
2 parents 7dcc7b8 + 5dae13c commit 704b574
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 126 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CohortSymmetry
Title: Sequence Symmetry Analysis Using the Observational Medical
Outcomes Partnership Common Data Model
Version: 0.1.5
Version: 0.2.0
Authors@R: c(
person("Xihang", "Chen", , "xihang.chen@ndorms.ox.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0009-0001-8112-8959")),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-generateSequenceCohortSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test_that("one ID against one ID, example 1", {
)

test_that("one ID against one ID, example 2", {
skip_on_cran()
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(cdm,
name = "joined_cohorts",
Expand Down
33 changes: 16 additions & 17 deletions vignettes/a01_Introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ cdm <- emptyCdmReference(cdmName = "mock") |>
con <- dbConnect(duckdb::duckdb())
cdm <- copyCdmTo(con = con, cdm = cdm, schema = "main", overwrite = T)
cdm$index_cohort |>
dplyr::glimpse()
cdm$marker_cohort |>
dplyr::glimpse()
```

Once we have established a connection to the database, we can use the `generateSequenceCohortSet()` function to find the intersection of the two cohorts. This function will provide us with the individuals who appear in both cohorts, which will be named **intersect** - another cohort in the cdm reference.
Expand All @@ -95,30 +89,35 @@ cdm$intersect |>
dplyr::glimpse()
```

Once we have the intersect cohort, you are able to explore the temporal symmetry by using `summariseTemporalSymmetry` and `plotTemporalSymmetry()`:
Once we have the intersect cohort, you are able to explore the temporal symmetry by using `summariseTemporalSymmetry`, `tableTemporalSymmetry`, and `plotTemporalSymmetry()`:

```{r message= FALSE, warning=FALSE}
temporal_symmetry <- summariseTemporalSymmetry(
cohort = cdm$intersect,
timescale = "year")
```
The result can be viewed using table and plot functions.

```{r message= FALSE, warning=FALSE}
result <- summariseTemporalSymmetry(cohort = cdm$intersect,
timescale = "year")
result |> dplyr::glimpse()
tableTemporalSymmetry(result = temporal_symmetry)
```

plotTemporalSymmetry(result = result)
```{r message= FALSE, warning=FALSE}
plotTemporalSymmetry(result = temporal_symmetry)
```

Next, we will use the `summariseSequenceRatios()` function to get the crude sequence ratios, adjusted sequence ratios, and the corresponding confidence intervals.
```{r message= FALSE, warning=FALSE}
result <- summariseSequenceRatios(cohort = cdm$intersect)
result |> dplyr::glimpse()
sequence_ratio <- summariseSequenceRatios(cohort = cdm$intersect)
```
Finally, we can visualise the results using `tableSequenceRatios()`:
```{r message= FALSE, warning=FALSE}
tableSequenceRatios(result)
tableSequenceRatios(result = sequence_ratio)
```
Or create a plot with the adjusted sequence ratios:

Or create a plot with the adjusted sequence ratios:
```{r message= FALSE, warning=FALSE}
plotSequenceRatios(result = result)
plotSequenceRatios(result = sequence_ratio)
```

## As a diagram
Expand Down
34 changes: 0 additions & 34 deletions vignettes/a03_Summarise_sequence_ratios.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,6 @@ summariseSequenceRatios(

The obtained output has a summarised result format. In the later vignette (**Step 3. Visualise results**) we will explore how to visualise the results in a more intuitive way.

## Modify the cohort based on `cohort_definition_id`

This parameter is used to subset the cohort table inputted to the `summariseSequenceRatios()`. Imagine the user only wants to include `cohort_definition_id` $= 1$ from `cdm$intersect` in the `summariseSequenceRatios()`, then one could do the following:

```{r message= FALSE, warning=FALSE}
summariseSequenceRatios(cohort = cdm$intersect,
cohortId = 1) |>
dplyr::glimpse()
```

Of course in this case this does nothing because every entry in `cdm$intersect` has `cohort_definition_id` $= 1$.

## Modify `confidenceInterval`
By default, the `summariseSequenceRatios()` function will use 95% (two-sided) confidence interval. If another confidence interval is desired, for example 99% confidence interval, one can use the `confidenceInterval` argument:
```{r message = FALSE, warning = FALSE}
summariseSequenceRatios(
cohort = cdm$intersect,
confidenceInterval = 99) |>
dplyr::glimpse()
```

## Modify `movingAverageRestriction`
The idea of moving average restriction is necessary only for the null sequence ratio calculation, please refer to Lai et al. (2017) for more details on this parameter (parameter d when calculating P in page 578). Following Tsiropoulos et al. (2009), by default, the argument `movingAverageRestriction` is set to be $548$ ($18$ months).

## Modify `minCellCount`

By default, the minimum number of events to reported is 5, below which results will be obscured. If 0, all results will be reported and the user could do this via:

```{r message= FALSE, warning=FALSE}
summariseSequenceRatios(cohort = cdm$intersect,
minCellCount = 0) |>
dplyr::glimpse()
```

```{r message= FALSE, warning=FALSE, eval=FALSE}
CDMConnector::cdmDisconnect(cdm = cdm)
```
23 changes: 0 additions & 23 deletions vignettes/a04_Visualise_sequence_ratios.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,6 @@ plotSequenceRatios(result = result,
colours = "red")
```

## Modify `plotTitle`

One could set the title like so:

```{r message= FALSE, warning=FALSE}
plotSequenceRatios(result = result,
onlyASR = T,
plotTitle = "Adjusted Sequence Ratio",
colour = "black")
```

## Modify `labs`

One could also change the $x$ and $y$ labels like so:

```{r message= FALSE, warning=FALSE}
plotSequenceRatios(result = result,
onlyASR = T,
plotTitle = "Adjusted Sequence Ratio",
colour = "black",
labs = c("sequence ratios", "analysis"))
```

```{r message= FALSE, warning=FALSE, eval=FALSE}
CDMConnector::cdmDisconnect(cdm = cdm)
```
10 changes: 0 additions & 10 deletions vignettes/a05_Summarise_temporal_symmetry.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ summariseTemporalSymmetry(cohort = cdm$intersect,
dplyr::glimpse()
```

## Modify `minCellCount`

By default, the minimum number of events to reported is 5, below which results will be obscured. If 0, all results will be reported and the user could do this via:

```{r message= FALSE, warning=FALSE}
summariseTemporalSymmetry(cohort = cdm$intersect,
minCellCount = 0) |>
dplyr::glimpse()
```

```{r message= FALSE, warning=FALSE, eval=FALSE}
CDMConnector::cdmDisconnect(cdm = cdm)
```
45 changes: 4 additions & 41 deletions vignettes/a06_Visualise_temporal_symmetry.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,53 +76,16 @@ Let's regather the output from `summariseTemporalSymmetry()`
temporal_symmetry <- summariseTemporalSymmetry(cohort = cdm$intersect)
```

With this established, much like `summariseSequenceRatios()`, the object `temporal_symmetry` could then be fed into `summariseTemporalSymmetry()` to visualise the results:
With this established, much like `summariseSequenceRatios()`, the object `temporal_symmetry` could then be fed into `tableTemporalSymmetry()` or `plotTemporalSymmetry()` to visualise the results:

```{r message= FALSE, warning=FALSE}
plotTemporalSymmetry(result = temporal_symmetry)
```
Note that the $x$ axis is the time, which we recall to be the initiation of the marker minus the initiation of the index. The unit of the time difference here is month as this is the default from `summarisTemporalSymmetry()`.

## Modify `xlim` and `labs`

If one changes the `timescale` for `summarisTemporalSymmetry()` to be `day` then logically one should change the `xlim` and `labs` accordingly like so:

```{r message= FALSE, warning=FALSE}
temporal_symmetry_day <- summariseTemporalSymmetry(cohort = cdm$intersect, timescale = "day")
plotTemporalSymmetry(result = temporal_symmetry_day,
labs = c("Time (days)", "Individuals (N)"),
xlim = c(-365, 365))
tableTemporalSymmetry(result = temporal_symmetry)
```

## Modify `plotTitle`

Much like what we already saw in **Step 3. Visualise the sequence ratios**. One could do the following:

```{r message= FALSE, warning=FALSE}
plotTemporalSymmetry(result = temporal_symmetry,
plotTitle = "Plot Temporal Symmetry")
```

## Modify `colours`

`colours` could be modified like so (remember two colours are required):

```{r message= FALSE, warning=FALSE}
plotTemporalSymmetry(result = temporal_symmetry,
colours = c("orange", "purple"))
```

## Modify `scales`

The `scale` parameter is designed for the users to have a choice as to whether to set free y scales for the facet wrap when there are multiple plots (i.e. each plot has its own scaled y axis) or set them equal for all. Only accepts "free" for the former and "fixed" for the latter.

For the `cdm$intersect` we have, it does not make a difference setting it to "fixed" or "free" (default). However, should one wish to set it to "fixed", one should do:

```{r message= FALSE, warning=FALSE, eval=FALSE}
plotTemporalSymmetry(result = temporal_symmetry,
scales = "fixed")
plotTemporalSymmetry(result = temporal_symmetry)
```
Note that the $x$ axis is the time, which we recall to be the initiation of the marker minus the initiation of the index. The unit of the time difference here is month as this is the default from `summarisTemporalSymmetry()`.

```{r message= FALSE, warning=FALSE, eval=FALSE}
CDMConnector::cdmDisconnect(cdm = cdm)
Expand Down

0 comments on commit 704b574

Please sign in to comment.