Last updated: 2025-10-16

Checks: 7 0

Knit directory: CPLASS/

This reproducible R Markdown analysis was created with workflowr (version 1.7.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20251014) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 95d44b7. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    data/.DS_Store

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/functions.Rmd) and HTML (docs/functions.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 95d44b7 Ldo3 2025-10-16 wflow_publish(c("analysis/functions.Rmd"))
html 892a230 Ldo3 2025-10-15 Build site.
Rmd a96e31a Ldo3 2025-10-15 update page
html a96e31a Ldo3 2025-10-15 update page
html 380b9e2 Ldo3 2025-10-15 Build site.
Rmd bebbb0b Ldo3 2025-10-15 wflow_publish(c("analysis/."))
html 442169c Ldo3 2025-10-14 Build site.
Rmd 5f97658 Ldo3 2025-10-14 Add custom CSS
html 5f97658 Ldo3 2025-10-14 Add custom CSS
html ef81878 Ldo3 2025-10-14 Build site.
Rmd 4a45b93 Ldo3 2025-10-14 wflow_publish(c("analysis/."))

All functions that used in this projects

CPLASS

Description

This function runs the Continuous Piecewise Linear Approximation with Stochastic Search (CPLASS) algorithm on a 2D data in the form of \((x_i,y_i)_{i=1}^n\) observed at time \((t_i)_{i=1}^n\) believed to follow a continuous piecewise linear regression model (Gaussian noise). It is used for detecting changes in velocity problem. CPLASS returns the time changes, the estimated parameters.

Usage

 CPLASS(t,x, y, lambda_r=1/30, 
                  iter_max = 5000, burn_in=500, s_cap=1, 
                  gamma=1.01, speed_pen=TRUE, Diagnostic = FALSE, 
                  sd = NA, pen = "ssic") 

Arguments

Argument Description
x A vector containing the data sequence (Cargo locations in x-axis)
y A vector containing the data sequence (Cargo locations in y-axis)
t A vector containing time
lambda_r the rate used in the proposal of a new vector of changepoints
iter_max The maximum number of iterations for running Metropolis-Hastings searching algorithm
burn_in The number of burn-in steps in MH search algorithm
s_cap The threshold for the output speed. If the inferred speed exceed s_cap and the speed_pen is activated, then the extra speed penalty will be introduced
gamma The power in the strengthened Schwarz Information Criterion (sSIC)
speed_pen If TRUE, adding the speed penalty to the penalty function; if FALSE, we only use the linear penalty term sSIC
Diagnostic If TRUE, a dataframe with all of update in the stochastic search will be printed
sd The standard deviation value of the noise of the data. If it is unknown, then CPLASS will estimate it.
pen Either aicc or ssic. The options to choose the information criterion. aicc for the Corrected Akaike Information Criterion, ssic for the strengthened Schwarz Information Criterion.

Output

A list of segment_inferred and path_inferred will be returned after running the algorithm.

Columns Description
cp_times The inferred change times
durations The inferred segment durations
states A binary vector labeling the state of the associated segments, 0 for stationary, 1 for motile. The labels are created using the cut-off method with a threshold of 100nm/s
speeds The inferred segment speeeds
vx The inferred velocity with respect to x-axis
vy The inferred velocity with respect to y-axis
Columns Description
t The input time
j The label of time points corresponding to the labels of segments after using the cut-off method
x The observed data with respect to x-axis
y The observed data with respect to y-axis
a The inferred piecewise linear lines (anchor locations w.r.t x-axis)
b The inferred piecewise linear lines (anchor locations w.r.t y-axis)

Example

← CPLASS Analysis

CPLASS_paths

For running CPLASS on a collection of paths, we introduced the function CPLASS_paths.

Usage

CPLASS_paths(data, PARALLEL = FALSE,
                        lambda_r=1/30, iter_max = 5000, burn_in=500, 
                        s_cap=1, gamma=1.01, speed_pen=TRUE, sd = NA,
                        pen = "ssic")

Arguments

Argument Description
data A list of paths where for each path we can specify \(t,x,y\)
PARALLEL If TRUE, running parallel computing; if FALSE, running sequentially
lambda_r the rate used in the proposal of a new vector of changepoints
iter_max The maximum number of iterations for running Metropolis-Hastings searching algorithm
burn_in The number of burn-in steps in MH search algorithm
s_cap The threshold for the output speed. If the inferred speed exceed s_cap and the speed_pen is activated, then the extra speed penalty will be introduced
gamma The power in the strengthened Schwarz Information Criterion (sSIC)
speed_pen If TRUE, adding the speed penalty to the penalty function; if FALSE, we only use the linear penalty term sSIC
sd The standard deviation value of the noise of the data. If it is unknown, then CPLASS will estimate it.
pen Either aicc or ssic. The options to choose the information criterion. aicc for the Corrected Akaike Information Criterion, ssic for the strengthened Schwarz Information Criterion.

Output

A list of paths, in each path, there is a similar output with two sublists segments_inferred and path_inferred as described in the CPLASS function.

Warnings

At the moment, we do not encourage using CPLASS_paths unless you provide the correct format of the data so that CPLASS_paths can read it. We are working on updating this function so that it is more user-friendly in the near future. To run CPLASS with a list of paths, please click here ← CPLASS Analysis.

plot_path_inferred

Description

This function return a plot for a segmented path after running CPLASS.

Usage

plot_path_inferred(path_info,xy_width = NA,t_lim = NA, motor, max_speed, state_shaded = TRUE, title_ind = NA, show_time_changes = FALSE)

Arguments

Argument Description
path_info A list of segmented trajectory. The trajectory must contain the two sublists including path_inferred and segment_inferred information as CPLASS output.
xy_width Adjust the frame size of the plot
t_lim The limit of t in the plot
motor Title of the plot, e.g., motor = "Kinesin"
lambda_r The rate used in the proposal of a new vector of changepoints
max_speed The maximum speed among all collection of inferred segment speeds after running CPLASS
state_shaded TRUE for showing the color of the motile/stationary segments
title_ind TRUE for showing index of paths, e.g., path 1, path 2
show_time_changes TRUE for showing the change times in the plot with dashed lines

Output

A plot with four panels showing the xy plot, x-vs-t, y-vs-t, and a plot on segment durations/segment speeds.

Example

← Visualization examples

plot_path_actual_and_inferred

Description

This function return a plot for a simulated trajectory where we can compare the actual vs inferred trajectories.

Usage

plot_path_actual_and_inferred(path_info, xy_width = NA, t_lim = NA, state_shaded = TRUE)

Arguments

Argument Description
path_info A list of segmented trajectory. The trajectory must contain the two sublists including path_inferred and segment_inferred information as CPLASS output.
xy_width Adjust the frame size of the plot
t_lim The limit of t in the plot
motor Title of the plot, e.g., motor = "Kinesin"
state_shaded TRUE for showing the color of the motile/stationary segments

Output

A plot with four panels showing the xy plot, x-vs-t, y-vs-t, and a plot on segment durations/segment speeds.

Example

← Visualization examples

plot_csa

Description

This function return a plot for a simulated trajectory where we can compare the actual vs inferred trajectories.

Usage

plot_csa(csa, legend = TRUE)

Arguments

Argument Description
csa A data frame that include calculated CSAs
legend TRUE show the legend of the plot

Output

CSA plot

Example

← Visualization examples


sessionInfo()
R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] workflowr_1.7.2

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       httr_1.4.7        cli_3.6.5         knitr_1.50       
 [5] rlang_1.1.6       xfun_0.53         stringi_1.8.7     processx_3.8.6   
 [9] promises_1.3.3    jsonlite_2.0.0    glue_1.8.0        rprojroot_2.1.1  
[13] git2r_0.36.2      htmltools_0.5.8.1 httpuv_1.6.16     ps_1.9.1         
[17] sass_0.4.10       rmarkdown_2.29    jquerylib_0.1.4   tibble_3.3.0     
[21] evaluate_1.0.4    fastmap_1.2.0     yaml_2.3.10       lifecycle_1.0.4  
[25] whisker_0.4.1     stringr_1.5.1     compiler_4.5.1    fs_1.6.6         
[29] pkgconfig_2.0.3   Rcpp_1.1.0        rstudioapi_0.17.1 later_1.4.3      
[33] digest_0.6.37     R6_2.6.1          pillar_1.11.0     callr_3.7.6      
[37] magrittr_2.0.3    bslib_0.9.0       tools_4.5.1       cachem_1.1.0     
[41] getPass_0.2-4