Learn R Programming

psc

The goal of psc is to compare a dataset of observations against a parametric model

Installation

You can install the development version of psc from GitHub with:

# install.packages("devtools")
devtools::install_github("richJJackson/psc")

Example

This is a basic example which shows you how to solve a common problem:

library(psc)
#> Warning: replacing previous import 'posterior::var' by 'stats::var' when
#> loading 'psc'
#> Warning: replacing previous import 'posterior::sd' by 'stats::sd' when loading
#> 'psc'
#> Warning: replacing previous import 'posterior::mad' by 'stats::mad' when
#> loading 'psc'
library(survival)
## basic example code

### Load model
data("surv.mod")

### Load Data
data("data")
#> Warning in data("data"): data set 'data' not found

### Use 'pscfit' to compare
surv.psc <- pscfit(surv.mod,data)
#> Warning in pscData_match(CFM$cov_class, CFM$cov_lev, DCcov): vi specified as a character in the model, consider respecifying
#>                 as a factor to ensure categories match between CFM and DC
#> Warning in pscData_match(CFM$cov_class, CFM$cov_lev, DCcov): allmets specified as a character in the model, consider respecifying
#>                 as a factor to ensure categories match between CFM and DC

You can use standard commands for getting a summary of your analysis…

summary(surv.psc)
#> Counterfactual Model (CFM): 
#> A model of class 'flexsurvreg' 
#>  Fit with 3 internal knots
#> 
#> CFM Formula: 
#> Surv(time, cen) ~ vi/age60 + ecog + allmets + logafp + alb + 
#>     logcreat + logast + aet
#> <environment: 0x11b23ef28>
#> 
#> CFM Summary: 
#> Expected response for the outcome under the CFM:
#>      S      lo      hi  
#>  9.694   9.094  10.653  
#> 
#> Observed outcome from the Data Cohort:
#>          [,1] 
#> median   6.366
#> 0.95LCL  5.436
#> 0.95UCL  9.094
#> 
#> MCMC Fit: 
#> Posterior Distribution obtaine with fit summary:
#>       variable    rhat        ess_bulk    ess_tail    mcse_mean 
#> [1,]  beta_1      1.000707    4222.245    3977.807    0.00151382
#> 
#> Summary: 
#> Posterior Distribution for beta:Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>            variable    mean        sd          median      q5        
#> posterior  beta_1      0.395547    0.09849599  0.3994494   0.229423  
#>            q95       
#> posterior  0.5514348

… and to see a plot of what you have done

#>            variable    mean        sd          median      q5        
#> posterior  beta_1      0.395547    0.09849599  0.3994494   0.229423  
#>            q95       
#> posterior  0.5514348
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.
#> ℹ The deprecated feature was likely used in the ggpubr package.
#>   Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> Ignoring unknown labels:
#> • colour : "Strata"

In that case, don’t forget to commit and push the resulting figure files, so they display on GitHub and CRAN.

Copy Link

Version

Install

install.packages('psc')

Monthly Downloads

549

Version

2.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Richard Jackson

Last Published

November 13th, 2025

Functions in psc (2.0.0)

plotCFM

Function for Plotting PSC objects
plot.psc.count

Function for Plotting PSC objects #' A function which illsutrates the predicted response under the counter factual model and the observed response under the experimental treatment(s).
modelExtract.glm

A generic function for extracting model information
count.mod

Example model for a survival outcome
summary.psc

Personalised Synthetic Controls - summary
pscData_addtrt

A function that includes a treatment indicator when multiple treatment comparisons are required
print.quiet_list

quiet_gtsumm
pscData_error

A function which performs error checks between the DC and CFM
modelExtract.lmerMod

A generic function for extracting model information
pscEst_run

Running the Bayesian MCMC routine A procedure which runs the MCMC estimation routine
plot.psc.binary

Function for Plotting PSC objects
pscEst_update

Updating the posterior distribution as part of the MCMC estimation process A procedure which performs a single update of the posterior distribution
pscCFM

Creating a CFM model which can be shared
pscEst_samp

Starting conditions for Bayesian MCMC estimation procedures in 'pscfit' A procedure which runs the sampling process for MCMC estimation
pscEst_start

Starting conditions for Bayesian MCMC estimation procedures in 'pscfit' A procedure which sets the starting conditions for MCMC estimation
psc.object

Fitted psc object
data

Example Dataset of patients with aHCC receiving Lenvetanib
psc-package

psc: Personalised Synthetic Controls
cfmDataVis

Visualising data within a CFM
cfmDataSumm

Summarising data within a Counter Factual Model (CFM)
surv.mod

Example model for a survival outcome
pscData

A function which structures the Data Cohort in a format for model estimation
print.quiet_gglist

quiet_gglist
pscEst

Function for performing Bayesian MCMC estimation procedures in 'pscfit'
print.quiet_gtsumm

quiet_gtsumm
pscData_structure

A function which structures the Data Cohort in a format for model estimation
pscfit

Personalised Synthetic Controls model fit
spline_surv_est

Counter Factual Model - summary
pscData_addLik

A function that add a likelihood for estimation to the pscObject
print.psc

Personalised Synthetic Controls - print
pscData_miss

A function which removes missing data from the DC
postSummary

Posterior Summary
pscData_match

A function to ensure that data from the cfm and data cohort are compatible
visComp

Visualising Comparisons between a CFM and a DC
lik.flexsurvreg

Likelihood function for a psc model of class 'flexsurvreg'
lik.glm

Likelihood function for a psc model of class 'glm'
numVisComp

Visualising Numerical Data
modp

modp
cfmDataVis_num

Visualising Numerical Data
boot_sest

Counter Factual Model - summary
boot_lp

Counter Factual Model - summary
cfmDataVis_fac

Visualising Categorical Data
cfmSumm.glm

Counter Factual Model - summary
bin.mod

Example model for a survival outcome
cfmSumm.flexsurvreg

Counter Factual Model - summary
acc

acc
coef.psc

Returns the coefficient estimate of a psc object.
facVisComp

Visualising Categorical Data
e4_data

Example Dataset of patients treated with GemCap in the ESPAC-4 trial
cont.mod

Example model for a survival outcome
plot.psc.cont

Function for Plotting PSC objects
plot.psc

Function for Plotting PSC objects
modelExtract.flexsurvreg

A generic function for extracting model information
init

Function for estimating initial parameter values
gemCFM

Model for a survival outcome based on Gemcitbine patients from ESPAC-3
modelExtract

A generic function for extracting model information
plot.psc.flexsurvreg

Function for Plotting PSC objects