Learn R Programming

tame (version 0.2.0)

summary_crop: Crop Clustering Summary

Description

Functions for cropping summarized cluster data.

Usage

summary_crop(object, ...)

# S3 method for cluster_frequency summary_crop(object, top_n = 5L, min_count = 0, min_percent = 0, ...)

# S3 method for medication_frequency summary_crop( object, top_n = 5L, min_count = 0, min_percent = 0, scope = "cluster", ... )

# S3 method for comedication_count summary_crop(object, ...)

# S3 method for timing_trajectory summary_crop(object, sample_n_individual = 100L, weighted_sample = TRUE, ...)

# S3 method for timing_atc_group summary_crop( object, sample_n_individual = 100L, weighted_sample = TRUE, min_count = 0L, ... )

# S3 method for summary.medic summary_crop(object, which = "all", ...)

Value

A summary object, which is a modified version of the input summary object.

Arguments

object

The summary object to be cropped.

...

Additional arguments to be passed to the specific method.

top_n

integer. In the case of cluster_frequency it is the number of clusters to keep. In the case of medication_frequency it is the number of medications to keep. If inf, all clusters or medications are kept.

min_count

integer. The minimum count of a cluster or medication to keep it in the summary. If 0, the default, the minimum count is zero, i.e. there is not a minimum count.

min_percent

numeric. The minimum percentage of a cluster or medication to keep it in the summary. If 0, the default, the minimum percentage is zero, i.e. there is not a minimum percentage.

scope

character. The scope of the summary crops top_n, min_count and min_percent. The options are "cluster" and "global". The default is "cluster". If "cluster", the crop is based on the percentage of medication in the cluster. If "global", the crop is based on the percentage of all medication.

sample_n_individual

a logical or integer. If FALSE, no individual timing trajectories are sampled. If integer, sample_n_individual is the number of individual timing trajectories to sample. To sample all individual timing trajectories, set sample_n_individual to Inf.

weighted_sample

a logical, but only used if sample_n_individual is an integer. If TRUE, the individual timing trajectories are sampled weighted by the number of medications in the individual timing trajectory. If FALSE, the individual timing trajectories are sampled uniformly.

which

A character vector specifying which summaries to crop. The options are "cluster_frequency", "medication_frequency", "comedication_count", "timing_trajectory", and "timing_atc_group". The default is "all".

<code>cluster_frequency</code> summary crop

Extracts the top top_n clusters by count. If top_n is Inf, all clusters are kept. If min_count is greater than 0, clusters with a count less than min_count are removed. If min_percent is greater than 0, clusters with a percentage less than min_percent are removed. The remaining clusters are grouped into a "Remaining" cluster.

<code>medication_frequency</code> summary crop

Extracts the top top_n medications by count. If top_n is Inf, all medications are kept. If min_count is greater than 0, medications with a count less than min_count are removed. If min_percent is greater than 0, medications with a percentage less than min_percent are removed. The remaining medications are grouped into a "Remaining" cluster.

The scope argument determines the scope of the crop. If scope is "cluster", the crop is based on the percentage of medication in the cluster. If scope is "global", the crop is based on the percentage of all medication.

<code>comedication_count</code> summary crop

TO DO

<code>timing_trajectory</code> summary crop

Samples sample_n_individual individual timing trajectories. If sample_n_individual is Inf, all individual timing trajectories are kept. If weighted_sample is TRUE, the individual timing trajectories are sampled weighted by the number of medications in the individual timing trajectory.

<code>timing_atc_group</code> summary crop

Samples sample_n_individual individual timing trajectories. If sample_n_individual is Inf, all individual timing trajectories are kept. If weighted_sample is TRUE, the individual timing trajectories are sampled weighted by the number of medications in the individual timing trajectory.

<code>summary.medic</code> summary crop

Crops multiple summaries. The which argument is a character vector specifying which summaries to crop. The options are "cluster_frequency", "medication_frequency", "comedication_count", "timing_trajectory", and "timing_atc_group". If which is "all", all summaries are cropped.

The ... argument is passed to the specific methods, e.g. top_n and min_count are passed to cluster_frequency and medication_frequency.

See Also

summary, cluster_frequency, medication_frequency, comedication_count, timing_trajectory, timing_atc_group

Examples

Run this code
clust <- medic(
  complications,
  id = id,
  atc = atc,
  k = 3:5,
  timing = first_trimester:third_trimester
)


# Crop the cluster frequency summary
clust |>
  cluster_frequency() |>
  summary_crop(top_n = 3)

clust |>
  summary() |>
  summary_crop(which = "cluster_frequency", top_n = 3)


# Crop the medication frequency summary
clust |>
  medication_frequency() |>
  summary_crop(top_n = 3)

clust |>
  summary() |>
  summary_crop(which = "medication_frequency", top_n = 3)


# Crop the co-medication count summary
clust |>
  comedication_count() |>
  summary_crop(min_count = 10)

clust |>
  summary() |>
  summary_crop(which = "comedication_count", min_count = 10)


# crop the timing trajectory summary
clust |>
  timing_trajectory() |>
  summary_crop()

clust |>
  summary() |>
  summary_crop(which = "timing_trajectory")


# crop the timing ATC group summary
clust |>
  timing_atc_group() |>
  summary_crop()

clust |>
  summary() |>
  summary_crop(which = "timing_atc_group")

# crop multiple summaries
clust |>
  summary() |>
  summary_crop(
    which = c("cluster_frequency", "medication_frequency"),
    top_n = 3
  )

Run the code above in your browser using DataLab