Title: | Perform the Weighted Multiplier Method on Trees |
---|---|
Description: | When many possible multiplier method estimates of a target population are available, a weighted sum of estimates from each back-calculated path can be achieved with this package. Variance-minimizing weights are used and with any admissible tree-structured data. The methodological basis used to create this package can be found in Flynn (2023) <http://hdl.handle.net/2429/86174>. |
Authors: | Mallory J Flynn [cre, aut] |
Maintainer: | Mallory J Flynn <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2024-10-25 05:24:49 UTC |
Source: | CRAN |
Estimation helper function: Method that takes samples and generates confidence intervals for nodes other than the root. Assume raw data (not log), with normal distributed log data for confidence interval construction
confInts(v)
confInts(v)
v |
A vector |
Returns a confidence interval. For non-root nodes
data(treeData1) tree <- makeTree(treeData1) message("note - longer run time example") Zhats <- wmmTree(tree, sample_length = 10) confInts(Zhats$estimates)
data(treeData1) tree <- makeTree(treeData1) message("note - longer run time example") Zhats <- wmmTree(tree, sample_length = 10) confInts(Zhats$estimates)
Visualize post-wmmTree tree with root estimate and marginal counts Also displays average of probability samples on each branch
countTree(tree)
countTree(tree)
tree |
A makeTree object |
Returns a tree plot
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) countTree(tree)
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) countTree(tree)
Visualize tree with descriptions and probabilities; can be used pre-WMM analysis
drawTree(tree, probs = TRUE, desc = TRUE)
drawTree(tree, probs = TRUE, desc = TRUE)
tree |
A makeTree object |
probs |
A logical with default TRUE to specify whether to display probabilities on branches |
desc |
A logical with default TRUE to specify whether to display node descriptions |
Returns a descriptive tree plot
data(treeData1) tree <- makeTree(treeData1) drawTree(tree)
data(treeData1) tree <- makeTree(treeData1) drawTree(tree)
Visualize post-wmmTree tree with root estimate given by each branch, and weighted sum at the root (for post-analysis). Also displays average of probability samples on each branch.
estTree(tree)
estTree(tree)
tree |
A makeTree object |
Returns a tree plot
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) estTree(tree)
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) estTree(tree)
Estimation helper function: Calculating variance minimizing weights. Only assigns weights to informative paths
ko.weights(tree)
ko.weights(tree)
tree |
A makeTree object |
Returns vector of variance-minimizing weights on informative paths
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ko.weights(tree)
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ko.weights(tree)
Estimation helper function: Creates a vector of mean estimate values given by each informative path
logEstimates(tree)
logEstimates(tree)
tree |
A makeTree object |
Returns a vector of mean log estimate values of the root population size from each informative path
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) logEstimates(tree)
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) logEstimates(tree)
Assuming a specific structure, create a tree with the following columns: from (node label), to (node label), Estimate (+ integer), Total (+ integer), and Count (for terminal nodes with marginal counts). 'from' and 'to' describe the edge for that row of data, where 'Estimate' and 'Total' are assumed to come from surveys of size 'Total' (a sample of the population at node 'from'), and observe 'Estimate' number of those individuals at 'Total' which move to the node described by 'to'. 'Estimate' and 'Total' columns are used for branching probabilities only. 'Count' column is NA for rows where 'to' nodes are not leaves; and also for all leaves without a marginal count. A Population (logical) column is not needed, but can be added if 'Estimate' and 'Total' come from population numbers, rather than samples. A 'Description' column (string) is also possible to include if particulars are desired on the tree diagram. 'TerminalCount' (binary) will be created for functional purposes, where marginal counts are included on leaves.
makeTree(data)
makeTree(data)
data |
A dataframe object |
Returns a makeTree object
data(treeData1) tree <- makeTree(treeData1)
data(treeData1) tree <- makeTree(treeData1)
Helper function: Performs the multiplier method from a single terminal node (o) and returns the root estimate given that path, and the probabilities of each branch on that path.
mmEstimate(o)
mmEstimate(o)
o |
A node from a makeTree object |
Returns node with modified attributes
data(treeData1) tree <- makeTree(treeData1) mmEstimate(tree$A) mmEstimate(tree$B) tree$A$targetEst tree$B$targetEst
data(treeData1) tree <- makeTree(treeData1) mmEstimate(tree$A) mmEstimate(tree$B) tree$A$targetEst tree$B$targetEst
Estimation helper function: Returns Nhat for each sample from the WMM (rather than the aggregate value given by the average, this calculates weights and applies the weighted sum to each of the samples)
Nhats(tree)
Nhats(tree)
tree |
A makeTree object |
Returns a vector of root population size estimates from each sample run of the wmmTree function
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) Nhats(tree)
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) Nhats(tree)
Estimation helper function: Method for generating confidence interval for root node. Assumes unlogged input data and normally distributed logged data. Completes conversion internally.
root.confInt(tree, int.type = "quantiles")
root.confInt(tree, int.type = "quantiles")
tree |
A makeTree object |
int.type |
A string specifying interval type, passed from the wmmTree function. |
Returns a confidence interval for the root population size estimate in un-logged form.
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) root.confInt(tree)
message("note - longer run time example") data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) root.confInt(tree)
Helper function: Method for sampling from a Beta distribution given the survey estimates
sampleBeta(x, n, pop, node)
sampleBeta(x, n, pop, node)
x |
An integer; typical use case is survey numerator |
n |
An integer; typical use case is survey sample size |
pop |
A logical value which takes TRUE if sample size is population size |
node |
A node from a makeTree object; carried forever from |
Returns sample from Beta distribution with parameters dependent on x, n
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) sampleBeta(10, 55, pop = FALSE, tree$A)
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) sampleBeta(10, 55, pop = FALSE, tree$A)
Estimation helper function: Method that takes samples and generates confidence intervals for nodes in single source sibling tree (single.source = TRUE)
ss.confInts(o, digits = 3)
ss.confInts(o, digits = 3)
o |
A node of a makeTree object |
digits |
The number of significant digits to report |
A confidence interval for nodes of the tree that only use a single source of sibling data.
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ss.confInts(tree$B)
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ss.confInts(tree$B)
Helper function: Performs the closed form calculation of variances and means based on a "single-source sibling" tree. Engages when single.source = TRUE in wmmTree function. See documentation for further details.
ssEstimate(o)
ssEstimate(o)
o |
A node from a makeTree object |
Returns node with modified attributes
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ssEstimate(tree$B)
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) ssEstimate(tree$B)
Small, artificially generated toy data set to demonstrate package functionality
data(treeData1)
data(treeData1)
An object of class "data.frame"
A node label and started point of directed edge (parent node)
A node label and endpoint of directed edge (child node)
A numerical value assumed to be survey count belonging to 'to' node (integer)
A numerical value assumed to be survey sample size (integer)
A numerical value for marginal count if leaf node (integer)
A boolean value for if survey size is entire population (logical)
A string describing 'to' node (string)
This data set was artificially created for the AutoWMM package.
data(treeData1) head(treeData1)
data(treeData1) head(treeData1)
Larger artificially generated toy data set to demonstrate package functionality
data(treeData2)
data(treeData2)
An object of class "data.frame"
A node label and started point of directed edge (parent node)
A node label and endpoint of directed edge (child node)
A numerical value assumed to be survey count belonging to 'to' node (integer)
A numerical value assumed to be survey sample size (integer)
A numerical value for marginal count if leaf node (integer)
This data set was artificially created for the AutoWMM package.
data(treeData2) head(treeData2)
data(treeData2) head(treeData2)
Main function. Generate weighted estimates using the weighted multiplier method.
wmmTree( tree, sample_length = 10, method = "mmEstimate", int.type = "quants", single.source = FALSE )
wmmTree( tree, sample_length = 10, method = "mmEstimate", int.type = "quants", single.source = FALSE )
tree |
A makeTree object |
sample_length |
An integer for number of samples |
method |
Method specifying weighting. Only default compatible with 'mmEstimate' at this time |
int.type |
A string specifying interval type. Default "quants" generates the interval using the quantiles giving the central 95% of the samples. Alternatively, "var" can be used to generate a variance-weighted confidence interval, and "cox" generates a Cox interval. |
single.source |
Set to TRUE if all data comes from single, fully informed source. Default is FALSE. |
Returns a makeTree object with branches and nodes now associated with estimates and samples generated with the weighted multiplier method
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) message("Another example with a larger tree") message("note - longer run time example") data(treeData2) tree2 <- makeTree(treeData2) Zhats <- wmmTree(tree2, sample_length = 3) Zhats$estimates # print the estimates of the root node generated by the 15 iterations Zhats$weights # prints the weights of each branch Zhats$root # prints the final estimate of the root node by WMM Zhats$uncertainty # prints the final rounded estimate of the root with conf. int. message(paste("show the average root estimate with 95% confidence interval,", "as well as average estimates with confidence interval for each parameter")) tree2$Get('uncertainty') message("show the samples generated from each path which provides root estimates") tree2$Get('targetEst_samples') message("show the probabilities sampled at each branch leading into the given node") tree2$Get('probability_samples')
data(treeData1) tree <- makeTree(treeData1) Zhats <- wmmTree(tree, sample_length = 3) message("Another example with a larger tree") message("note - longer run time example") data(treeData2) tree2 <- makeTree(treeData2) Zhats <- wmmTree(tree2, sample_length = 3) Zhats$estimates # print the estimates of the root node generated by the 15 iterations Zhats$weights # prints the weights of each branch Zhats$root # prints the final estimate of the root node by WMM Zhats$uncertainty # prints the final rounded estimate of the root with conf. int. message(paste("show the average root estimate with 95% confidence interval,", "as well as average estimates with confidence interval for each parameter")) tree2$Get('uncertainty') message("show the samples generated from each path which provides root estimates") tree2$Get('targetEst_samples') message("show the probabilities sampled at each branch leading into the given node") tree2$Get('probability_samples')