stepfun.hist {ConnMatTools}R Documentation

Create a probability density step function from a histogram object

Description

This function creates a step function from the bars in a histogram object. By default, the step function will be normalized so that it integrates to 1.

Usage

stepfun.hist(h, ..., normalize = TRUE)

Arguments

h

an object of type histogram

...

Additional arguments for the default stepfun function.

normalize

Boolean indicating whether or not to normalize the output stepfun so that it integrates to 1. Defaults to TRUE. If FALSE, then the function will integrate to sum(h$counts)

Value

A function of class stepfun. The height of the steps will be divided by the distance between breaks and possibly the total count.

Author(s)

David M. Kaplan dmkaplan2000@gmail.com

See Also

See also d.rel.conn.dists.func, optim.rel.conn.dists.

Examples

library(ConnMatTools)
data(damselfish.lods)

# Histograms of simulated LODs
l <- seq(-1,30,0.5)
h.in <- hist(damselfish.lods$in.group,breaks=l)
h.out <- hist(damselfish.lods$out.group,breaks=l)

# PDFs for marked and unmarked individuals based on simulations
d.marked <- stepfun.hist(h.in)
d.unmarked <- stepfun.hist(h.out)

# Fraction of adults genotyped at source site
p.adults <- 0.25

# prior.shape1=1 # Uniform prior
prior.shape1=0.5 # Jeffreys prior

# Fraction of eggs from one or more genotyped parents
p <- dual.mark.transmission(p.adults)$p

# PDF for relative connectivity
D <- d.rel.conn.dists.func(damselfish.lods$real.children,
                           d.unmarked,d.marked,p,
                           prior.shape1=prior.shape1)

# Estimate most probable value for relative connectivity
phi.mx <- optim.rel.conn.dists(damselfish.lods$real.children,
                                    d.unmarked,d.marked,p)$phi

# Estimate 95% confidence interval for relative connectivity
Q <- q.rel.conn.dists.func(damselfish.lods$real.children,
                           d.unmarked,d.marked,p,
                           prior.shape1=prior.shape1)

# Plot it up
phi <- seq(0,1,0.001)
plot(phi,D(phi),type="l",
     xlim=c(0,0.1),
     main="PDF for relative connectivity",
     xlab=expression(phi),
     ylab="Probability density")

abline(v=phi.mx,col="green",lty="dashed")
abline(v=Q(c(0.025,0.975)),col="red",lty="dashed")

[Package ConnMatTools version 0.3.5 Index]