R/RcppExports.R

Defines functions update_onward_transmission onward_check log_lik_transmission_patient_subset log_lik_transmission log_lik_sources log_lik_rho log_lik_overall_with_types log_lik_overall log_lik_importation get_ap_with_types get_ap daily_col_prob_precalculated daily_col_prob count_true_positive_tests count_tests_forward_simulations count_false_negative_tests col_pop

Documented in col_pop count_false_negative_tests count_tests_forward_simulations count_true_positive_tests daily_col_prob_precalculated log_lik_importation log_lik_overall log_lik_overall_with_types log_lik_rho log_lik_sources log_lik_transmission onward_check update_onward_transmission

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Count the number of colonised patients
#'
#' This function counts the number of colonised patients on and off antibiotics
#' on a given day.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonsiations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param day the day for which the colonised number of colonised patients
#' is counted.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @export
col_pop <- function(admissions, colonisations, discharges, statuses, day, antibiotics) {
    .Call(`_mrsamcmc_col_pop`, admissions, colonisations, discharges, statuses, day, antibiotics)
}

#' Count false negative tests
#'
#' This function counts the number of false negative tests conducted with and
#' without antibioitics.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param test_results_negative a matrix where each row corresponds to a patient
#' and the entries correspond to a day with a negative test result.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @export
count_false_negative_tests <- function(colonisations, statuses, test_results_negative, antibiotics) {
    .Call(`_mrsamcmc_count_false_negative_tests`, colonisations, statuses, test_results_negative, antibiotics)
}

#' Count positive and negative tests
#'
#' This function counts the positive and negative tests in the simulated
#' data generated by \code{run_forward_simulations()}.
#'
#' @param rho_1 the test sensitivity in the absence of antibiotics.
#'
#' @param rho_2 the test sensitivity in the presence of antibiotics.
#'
#' @param colonisations a vector of colonisation times of the patients.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param days_of_tests a matrix where each row corresponds to a patient
#' and the entries correspond to a day when a test was conducted.
#'
#' @param n_patients the total number of patients.
#'
#' @return This function returns a vector with two elements. The first number
#' is the total number of positive tests, the second number is the total
#' number of negative tests.
#'
#' @export
count_tests_forward_simulations <- function(rho_1, rho_2, colonisations, antibiotics, days_of_tests, n_patients) {
    .Call(`_mrsamcmc_count_tests_forward_simulations`, rho_1, rho_2, colonisations, antibiotics, days_of_tests, n_patients)
}

#' Count true positive tests.
#'
#' This function counts the number of true positive tests conducted with and
#' without antibioitics. We assume perfect specificity, so each positive test
#' is a true positive test.
#'
#' @param test_results_positive a matrix where each row corresponds to a patient
#' and the entries correspond to a day with a positive test result.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @export
count_true_positive_tests <- function(test_results_positive, antibiotics) {
    .Call(`_mrsamcmc_count_true_positive_tests`, test_results_positive, antibiotics)
}

#' Daily probability of acquisition
#'
#' This function calculates probability of acquisition for a given patient
#' on a given day.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#' @param day the day for which the probability of acquisition is computed.
#'
#' @param pt the patient for which the probability of acquisition is computed.
NULL

#' @export
daily_col_prob <- function(admissions, colonisations, discharges, statuses, antibiotics, beta, b, s, day, pt) {
    .Call(`_mrsamcmc_daily_col_prob`, admissions, colonisations, discharges, statuses, antibiotics, beta, b, s, day, pt)
}

#' Compute the probability of acquisition
#'
#' This function calculates the probability of acquisition for a given day
#' and patient using precalculated numbers of colonised patients on and off
#' antibiotics on the given day.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonsiations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param cp_no_abx the number of colonised patients not on antibiotics
#' on the given day.
#'
#' @param cp_abx the number of colonised patients on antibiotics
#' on the given day.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#' @param day the day for which the probability of acquisition is calculated.
#'
#' @param pt the patient for which the probability of acquisition is calculated.
#'
#'
#' @export
daily_col_prob_precalculated <- function(admissions, colonisations, discharges, statuses, antibiotics, cp_no_abx, cp_abx, beta, b, s, day, pt) {
    .Call(`_mrsamcmc_daily_col_prob_precalculated`, admissions, colonisations, discharges, statuses, antibiotics, cp_no_abx, cp_abx, beta, b, s, day, pt)
}

#' Get vector of patients eligible for colonisation removal
#'
#' This function returns a vector of patients who are eligible for removal
#' of colonisation. These are all patients who were never tested positive and
#' who are not the only possible source of infection for another patient.
#'
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param first_positive_test a vector with the days of the first positive
#' test of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param nPatients the total number of patients.
NULL

#' @export
get_ap <- function(admissions, colonisations, discharges, first_positive_test, statuses, nPatients) {
    .Call(`_mrsamcmc_get_ap`, admissions, colonisations, discharges, first_positive_test, statuses, nPatients)
}

#' Get vector of patients eligible for colonisation removal
#'
#' This function returns a vector of patients who are eligible for removal
#' of colonisation. These are all patients who were never tested positive and
#' who are not the only possible source of infection for another patient.
#'
#'
#' @param status a vector. the statuses on discharge of the patients.
#'
#' @param first_positive_test a vector with the days of the first positive
#' test of the patients.
#'
#' @param source a vector. the sources of the patients.
#'
#' @param nPatients the total number of patients.
NULL

#' @export
get_ap_with_types <- function(status, first_positive_test, source, nPatients) {
    .Call(`_mrsamcmc_get_ap_with_types`, status, first_positive_test, source, nPatients)
}

#' Log likelihood of importation
#'
#' This function calculates the importation component of the overall log
#' likelihood.
#'
#' @param nPatient the total number of patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param TP_no_abx the number of true positive tests without antibiotics.
#'
#' @param phi the probability of a patient beeing colonised on admission.
#'
#' @export
log_lik_importation <- function(nPatient, statuses, phi) {
    .Call(`_mrsamcmc_log_lik_importation`, nPatient, statuses, phi)
}

#' Overall log likelihood for one patient
#'
#' This function calculates the summand of the overall log likelihood that
#' changes when the status of one patient is updated. The constant summands
#' are ignored for efficiency.
#'
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param TP_no_abx the number of true positive tests without antibiotics.
#'
#' @param TP_abx the number of true positive tests with antibiotics.
#'
#' @param test_results_negative a matrix where each row corresponds to a
#' patient and the entries correspond to a day with a negative test result.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param beta the transmission rate.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#' @param rho_1 the test sensitivity without antibiotics (baseline).
#'
#' @param rho_2 the test sensitivity with antibiotics.
#'
#' @param nPatient the total number of patients.
#'
#' @param phi the probability of a patient beeing colonised on admission.
#'
#' @param pt the patient for which the overall log likelihood is computed.
#'
#' @export
log_lik_overall <- function(admissions, discharges, colonisations, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, beta, b, s, rho_1, rho_2, nPatient, phi, pt) {
    .Call(`_mrsamcmc_log_lik_overall`, admissions, discharges, colonisations, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, beta, b, s, rho_1, rho_2, nPatient, phi, pt)
}

#' Overall log likelihood for one patient
#'
#' This function calculates the summand of the overall log likelihood that
#' changes when the status of one patient is updated. The constant summands
#' are ignored for efficiency.
#'
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param sources a vector with the sources of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param TP_no_abx the number of true positive tests without antibiotics.
#'
#' @param TP_abx the number of true positive tests with antibiotics.
#'
#' @param test_results_negative a matrix where each row corresponds to a
#' patient and the entries correspond to a day with a negative test result.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#' @param rho_1 the test sensitivity without antibiotics (baseline).
#'
#' @param rho_2 the test sensitivity with antibiotics.
#'
#' @param nPatients the total number of patients.
#'
#' @param nTypes the number of types of colonisation.
#'
#' @param phi the probability of a patient beeing colonised on admission.
#'
#' @param pt the patient for which the overall log likelihood is computed.
#'
#' @export
log_lik_overall_with_types <- function(admissions, discharges, colonisations, sources, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, beta, b, s, rho_1, rho_2, nPatients, types, types_names, types_freq, nTypes, phi, pt) {
    .Call(`_mrsamcmc_log_lik_overall_with_types`, admissions, discharges, colonisations, sources, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, beta, b, s, rho_1, rho_2, nPatients, types, types_names, types_freq, nTypes, phi, pt)
}

#' Log likelihood of test sensitivity
#'
#' This function calculates the test sensitivity component of the overall log
#' likelihood.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param TP_no_abx the number of true positive tests without antibiotics.
#'
#' @param TP_abx the number of true positive tests with antibiotics.
#'
#' @param test_results_negative a matrix where each row corresponds to a patient
#' and the entries correspond to a day with a negative test result.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param rho_1 the test sensitivity without antibiotics (baseline).
#'
#' @param rho_2 the test sensitivity with antibiotics.
#'
#'
#' @export
log_lik_rho <- function(colonisations, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, rho_1, rho_2) {
    .Call(`_mrsamcmc_log_lik_rho`, colonisations, statuses, TP_no_abx, TP_abx, test_results_negative, antibiotics, rho_1, rho_2)
}

#' Log likelihood of sources
#'
#' This function calculates the source component of the overall log likelihood.
#'
#' @param nPatients the total number of patients.
#'
#' @param nTypes the number of differnt types of colonisations.
#'
#' @param admission a vector with days of admission of the patients.
#'
#' @param colonisation a vector with days of colonisation of the patients.
#'
#' @param source a vector with the sources of the patients.
#'
#' @param discharge a vector with days of discharge of the patients.
#'
#' @param status a vector with the statuses on discharge of the patients.
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @export
log_lik_sources <- function(nPatients, admission, colonisation, source, discharge, status, types, types_names, types_freq, nTypes, antibiotics, b) {
    .Call(`_mrsamcmc_log_lik_sources`, nPatients, admission, colonisation, source, discharge, status, types, types_names, types_freq, nTypes, antibiotics, b)
}

#' Log likelihood of transmission
#'
#' This function calculates the transmission component of the overall log
#' likelihood.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param cp_no_abx the number of colonised patients not on antibiotics
#' on the given day.
#'
#' @param cp_abx the number of colonised patients on antibiotics
#' on the given day.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#'
#' @export
log_lik_transmission <- function(admissions, colonisations, discharges, statuses, antibiotics, cp_no_abx, cp_abx, beta, b, s) {
    .Call(`_mrsamcmc_log_lik_transmission`, admissions, colonisations, discharges, statuses, antibiotics, cp_no_abx, cp_abx, beta, b, s)
}

#' Log likelihood of transmission for one patient
#'
#' This function calculates the summand of the transmission component of the
#' overall log likelihood that changes when the status of one patient is updated.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param antibiotics a matrix where each row corresponds to a patient
#' and the entries correspond to a day when antibiotics were administered.
#'
#' @param beta the transmission rate.
#'
#' @param b the multiplicative effect of antibiotics on transmissibility.
#'
#' @param s the multiplicative effect of antibiotics on susceptibility.
#'
#' @param pt the patient for which the likelihood is computed.
NULL

#'
#' @export
log_lik_transmission_patient_subset <- function(admissions, colonisations, discharges, statuses, antibiotics, beta, b, s, pt) {
    .Call(`_mrsamcmc_log_lik_transmission_patient_subset`, admissions, colonisations, discharges, statuses, antibiotics, beta, b, s, pt)
}

#' Get last possible day for colonisation
#'
#' This function returns the last day on which a patient can become colonised.
#' If an onward transmission depends on that patient, the last possible day is
#' the day before the onward tranmission. If not, it is the minimum of the
#' first positive test and discharge.
#'
#' @param pt the patient for which the onward transmission is calculated.
#'
#' @param admissions a vector with days of admission of the patients.
#'
#' @param colonisations a vector with days of colonisation of the patients.
#'
#' @param discharges a vector with days of discharge of the patients.
#'
#' @param first_positive_test a vector with the days of the first positive
#' test of the patients.
#'
#' @param statuses a vector the statuses on discharge of the patients
#'
#' @param nPatients the total number of patients.
#'
#' @export
onward_check <- function(pt, admissions, colonisations, discharges, first_positive_test, statuses, nPatients) {
    .Call(`_mrsamcmc_onward_check`, pt, admissions, colonisations, discharges, first_positive_test, statuses, nPatients)
}

#' Get first onward transmission of a patient
#'
#' This function returns the first onward transmission for a given patient.
#'
#'
#' @param pt an integer. the patient for which the first onward transmission
#' is returned.
#'
#' @param source a vector. the sources of the patients.
#'
#' @param colonisation a vector with days of colonisation of the patients.
#'
#' @param n_patients the total number of patients.
#' @export
update_onward_transmission <- function(pt, source, colonisation, n_patients) {
    .Call(`_mrsamcmc_update_onward_transmission`, pt, source, colonisation, n_patients)
}
mirjamlaager/mrsamcmc documentation built on May 20, 2020, 11:13 a.m.