rtmvnormDT3: Function to sample from the posterior of estimated genomic...

View source: R/rtmvnormDT3.r

rtmvnormDT3R Documentation

Function to sample from the posterior of estimated genomic cline parameters.

Description

Function to sample from the posterior of estimated genomic cline parameters.

Usage

rtmvnormDT3(
  nsamp = 1,
  meanlogv,
  meanlogitcentre,
  varlogv,
  varlogitcentre,
  covlogvlogitcentre,
  lower = c(-Inf, -Inf),
  upper = c(Inf, Inf)
)

Arguments

nsamp

Numeric. Number of random posterior samples. Default 1.

meanlogv

Name of the column in a data.table containing posterior mean values for ln(v), or another variable from a bivariate normal distribution. Entry should not include quotation marks. No default.

meanlogitcentre

Name of the column in a data.table containing mean values for logit(centre), or another variable from a bivariate normal distribution. Entry should not include quotation marks. No default.

varlogv

Name of the column in a data.table containing values for the posterior variance of ln(v), or another variable from a bivariate normal distribution. Entry should not include quotation marks. No default.

varlogitcentre

Name of the column in a data.table containing values for the posterior variance of logit(centre), or another variable from a bivariate normal distribution. Entry should not include quotation marks. No default.

covlogvlogitcentre

Name of the column in a data.table containing the posterior covariance between ln(v) and logit(centre), or any other pair of bivariate normally distributed variables. Entry should not include quotation marks. No default.

lower

Numeric vector. If truncation is desired, the lower cutoff for the two variables.

upper

Numeric vector. If truncation is desired, the upper cutoff for the two variables.

Details

rtmvnormDT3 is a generalized version of two internal gghybrid functions that themselves are designed for sampling from the parameter proposal distributions for ln(v) and logit(centre). Its purpose is to take samples from the joint posterior of the two parameters for one or more test subjects simultaneously. While the option names are specific to gghybrid, the column names are left open and so the function can be used to sample from any set of bivariate normal distributions, including with truncation.

The function must be run from within a data.table, which can be subsetted by row if desired, as shown in the example.

Value

A data.table and data.frame with one row per sample per test subject.

locus

the name of the chosen test.subject. If a test subject other than locus is chosen, the column will be named accordingly.

log_v

posterior samples of ln(v), or another chosen variable.

logit_centre

posterior samples of logit(centre), or another chosen variable.

Author(s)

Richard Ian Bailey richardianbailey@gmail.com

Examples


## Not run: 
##########################################################################
#Sample from the genomic cline parameter posteriors of a subset of 5 loci#
##########################################################################

#The function must be run from within a data.table, after the comma. Subsetting by row can be carried out.
#In this case I'm sampling from the 'gc' object created in the documentation examples for 'ggcline'.

gcsamp=gc$gc[locus%in%c("ACO1","CLTA","LNPEP","HSDL2","MCCC2"), #subsetting the data.table by row to only include these 5 loci#
 rtmvnormDT3(
  nsamp=500,                                 #default is 1 sample per locus#
  meanlogv=mean_log_v,                       #no default, column must be specified#
  meanlogitcentre=mean_logit_centre,         #no default, column must be specified#
  varlogv=var_log_v,                         #no default, column must be specified#
  varlogitcentre=var_logit_centre,           #no default, column must be specified#
  covlogvlogitcentre=cov_log_v_logit_centre, #no default, column must be specified#
  lower=c(-Inf,-Inf),                        #default, not needed for sampling from the ggcline posterior but included in case it's useful in other contexts#
  upper=c(Inf,Inf)                           #default, not needed for sampling from the ggcline posterior but included in case it's useful in other contexts#
            ),                               #end of rtmvnormDT3 function#
 by="locus"];                                #indicate a grouping variable for the sampling. This will be the name of the first column in the resulting table#

## End(Not run)

ribailey/gghybrid documentation built on Feb. 2, 2024, 12:53 a.m.