Package 'FreqEstimationModel'

Title: Multi-SNP Haplotype Frequency Estimation
Description: A method for multi-SNP haplotype frequency estimation.
Authors: Aimee Taylor [aut, cre]
Maintainer: Aimee Taylor <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-05 07:26:16 UTC
Source: https://github.com/aimeertaylor/FreqEstimationModel

Help Index


Calculate legal genotype count moves

Description

Function to calculate the genotype counts that can be removed without rendering the ensuing likelihood equal to zero

Usage

calculate_genotype_counts_truncated(
  genotype_counts,
  comp_genotypes,
  raw_data,
  moi_prior_min2
)

Calculate the log genotype counts proposal ratio

Description

Function to calculate the log genotype counts proposal ratio

Usage

calculate_log_genotype_counts_proposal_ratio(
  moi_diff,
  genotype_counts_diff,
  neg_log_sum_frequency_truncated,
  mh_genotype_counts_truncated,
  y_character,
  log_target_ratio,
  datasampleID,
  no_total
)

Calculate log MOI proposal ratio

Description

Function to calculate the log MOI proposal ratio

Usage

calculate_log_moi_proposal_ratio(
  moi_max,
  moi_current,
  moi_proposed,
  moi_current_equal_moi_min,
  moi_proposed_equal_moi_min,
  datasampleID,
  no_total
)

Compatible genotypes

Description

Function to ascertain the genotypes that are compatible with a given observation

Usage

compatible_genotypes(observation, as_numeric = TRUE)

Arguments

observation

A vector of allelic calls for a given individual, with one call per loci. Heteroallelic loci can either be encoded as 0.5. Alternatively, all alleles detected at heteroallelic loci can be listed. See examples below.

Examples

# Example where heteroallelic loci are encoded as 0.5
y <- c(0, 1, 0.5, 0.5)
compatible_genotypes(y)
compatible_genotypes(y, FALSE)

# Example where all alleles detected at heteroallelic loci are listed
y <- list(0, 1, c(0,1), c(0,1,2))
compatible_genotypes(y)
compatible_genotypes(y, FALSE)

Data genotype count compatibility

Description

Data and genotype compatibility check function

Usage

data_genotype_count_compatibility(comp_genotypes, genotype_counts, raw_data)

Dirichlet density

Description

Calculate the density of the dirichlet distribution. This function is exactly the same as that from MCMCpack, copied to minimise dependencies.

Usage

ddirichlet(x, alpha)

Draw frequency proposed child

Description

Function for drawing frequency proposed per child

Usage

draw_frequency_proposed_child(Alpha, genotype_counts_current)

Draw initial genotype counts

Description

Function for drawing initial genotype counts.

Usage

draw_genotype_counts_initial(
  moi_current,
  processed_data_list,
  frequency_current
)

Draw initial MOIs

Description

Function for drawing initial MOIs.

Usage

draw_moi_initial(moi_list, datasampleID, y_no_mxed, y_mxed)

Arguments

datasampleID

is a vector of sample IDs; that is, a character vector such as c('id1:1','id2:1','id3:1','id4:1'). It is required to ensure the order of the initial MOI estimates is consistent with the data.

y_no_mxed

is a vector comprising a subset of datasampleID; for example c('id1:1','id4:1'). The subset includes sample IDs for all samples for which there is no evidence of multiclonality; that is, samples for which an MOI of one is possible.

y_mxed

is a vector comprising a subset of datasampleID; for example c('id1:2','id4:3'). The subset includes sample IDs for all samples for which there is evidence of multiclonality; that is, samples for which an MOI of one is not possible. Note that, y_no_mxed and y_mxed are disjoints sets that together union of is equal to the unordered equivalent of datasampleID.

moi_list$moi_prior

is a character, either 'Poisson', 'nBinomial', 'Geometric' or 'Uniform', that defines the prior distribution over the MOI.

moi_list$moi_max

is an integer defining the maximum moi possible in the model

moi_list$moi_hyperparameter

is a parameter of the prior distribution

moi_list$moi_size_hyperparameter

is a parameter of the prior distribution


Propose MOI

Description

Function for drawing new MOI vector. Note that there is no option to stay still, and that Proposal density does not have equal probability over state space [m_min,..,m_max] and is not symmetric: Pr(m*|m)=Pr(m|m*)

Usage

draw_moi_proposed(moi_current, moi_current_equal_moi_min, moi_max)

Hello, World!

Description

Prints 'Hello, world!'.

Usage

hello()

Examples

hello()

Log likelihood, NGS data

Description

Calculate log likelihood of NGS data

Usage

log_likelihood_NGS(processed_data_list, genotype_counts)

Log likelihood, prevalence data

Description

Calculate log likelihood of prevalence data

Usage

log_likelihood_prevalence(processed_data_list, genotype_counts)

Log moi prior

Description

Log moi prior calculation

Usage

log_moi_prior_calculation_geom(moi_store, moi_list, y_no_mxed, y_mxed)

Log moi prior

Description

Log moi prior calculation

Usage

log_moi_prior_calculation_nbinom(moi_store, moi_list, y_no_mxed, y_mxed)

Log moi prior

Description

Log moi prior calculation

Usage

log_moi_prior_calculation_pois(moi_store, moi_list, y_no_mxed, y_mxed)

Log moi prior

Description

Log moi prior calculation

Usage

log_moi_prior_calculation_unif(moi_store, moi_list, y_no_mxed, y_mxed)

lLg prior MOI ratio

Description

Function to calculate the log of the prior MOI ratio when the MOI prior distribution is geometric. Note that the normalising constants due to truncation cancel.

Usage

log_prior_moi_ratio_geom(
  moi_proposed,
  moi_current,
  moi_hyperparameter,
  moi_size_hyperparameter
)

Log prior MOI ratio

Description

Function to calculate the log of the prior MOI ratio when the MOI prior distribution is negative binomial. Note that the normalising constants due to truncation cancel.

Usage

log_prior_moi_ratio_nbinom(
  moi_proposed,
  moi_current,
  moi_hyperparameter,
  moi_size_hyperparameter
)

Log prior MOI ratio

Description

Function to calculate the log of the prior MOI ratio when the MOI prior distribution is poisson. Note that the normalising constants due to truncation cancel.

Usage

log_prior_moi_ratio_pois(
  moi_proposed,
  moi_current,
  moi_hyperparameter,
  moi_size_hyperparameter
)

Log prior MOI ratio

Description

Function to calculate the log of the prior MOI ratio when the MOI prior distribution is a discrete uniform distribution. Note that the normalising constants due to truncation cancel.

Usage

log_prior_moi_ratio_unif(
  moi_proposed,
  moi_current,
  moi_hyperparameter,
  moi_size_hyperparameter
)

MCMC

Description

Function to implement mcmc sampler, which is embedded within data preprocessing and retrospective posterior calculations

Usage

mcmc_sampling(
  processed_data_list,
  moi_list,
  frequency_list,
  mcmc_variable_list
)

MCMC

Description

Function to implement mcmc sampler chains in parallel, followed retrospective posterior calculations

Usage

mcmc_sampling_parallel(
  processed_data_list,
  moi_list,
  frequency_list,
  mcmc_variable_list,
  cores_max,
  seed = 1234352
)

Arguments

processed_data_list

List of processed data

moi_list

List of MOI settings

frequency_list

List of frequency settings

mcmc_variable_list

List of MCMC settings

cores_max

Maximum number of cores to register with doMC

seed

Integer seed for the per-chain RNG streams built by RNGseq().


Log Multinomial Density

Description

Function to calculate the density of multiple realisations of the multinomial distribution simultaneously given either a single probability or a matrix of probability

Usage

my_log_dmultinom(x, prob, pop_fequency)

Preprocess data

Description

Function to preprocess data

Usage

preprocess_data(
  data_summary,
  log_like_zero,
  NGS,
  augment_missing_data,
  moi_prior_min2
)

Hello, Rcpp!

Description

Returns an R list containing the character vector c("foo", "bar") and the numeric vector c(0, 1).

Usage

rcpp_hello()

Examples

rcpp_hello()

Random draw from the dirichlet

Description

Same as the rdirichlet function in MCMCpack but rewritten to minimise dependencies.

Usage

rdirichlet(n, alpha)

Details

Need to add log option


Update genotype counts

Description

Function to update genotype counts conditional on current genotype counts and new multiplicity of infection (MOI)

Usage

update_genotype_counts(
  moi_diff,
  genotype_counts_current,
  current_genotype_counts_truncated,
  processed_data_list
)

Update mixed data samaple clone addition

Description

Function for addition of clone to a mixed data sample

Usage

update_y_mixed_add(to_update, genotype_counts_mixed_add, frequency_truncated)

Update mixed data samaple clone removal

Description

Function for removal of clone from mixed data sample

Usage

update_y_mixed_sub(
  to_update,
  genotype_counts_mixed_sub,
  genotype_counts_truncated
)