post_prob_states: Calculate posterior probability of each states/geographic...

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/BioGeoBEARS_detection_v1.R

Description

This function calculates P(range|data,detection model), i.e. the probability of each possible range, given a prior probability of each range, and the likelihood of each range.

Usage

1
2
  post_prob_states(prob_of_each_range,
    condlikes_of_data_on_each_range)

Arguments

prob_of_each_range

The probability of each range, given the prior probability of presence in each area.

condlikes_of_data_on_each_range

The probability of the data, conditional on each range (i.e., the likelihood), as found in e.g. a row of the output from tiplikes_wDetectionModel.

Details

The prior probability of each range should be considered by the user. Note that putting the same prior on the probability of occurrence in each individual range does NOT mean a flat prior on each state/geographic range. This fact is demonstrated in the function prob_of_states_from_prior_prob_areas.

Value

posterior_probs The posterior probability of each range.

Note

Go BEARS!

Author(s)

Nicholas J. Matzke matzke@berkeley.edu

References

http://phylo.wikidot.com/matzke-2013-international-biogeography-society-poster http://en.wikipedia.org/wiki/Log_probability

Matzke_2012_IBS

Bottjer_Jablonski_1988

See Also

prob_of_states_from_prior_prob_areas, tiplikes_wDetectionModel, rcpp_areas_list_to_states_list, Pdata_given_rangerow, calc_obs_like, mapply, read_detections, read_controls

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
testval=1

# soft-coded input files
extdata_dir = np(system.file("extdata", package="BioGeoBEARS"))
detects_fn = np(paste(extdata_dir, "/Psychotria_detections_v1.txt", sep=""))
controls_fn = np(paste(extdata_dir, "/Psychotria_controls_v1.txt", sep=""))

detects_df = read_detections(detects_fn, OTUnames=NULL, areanames=NULL, tmpskip=0)
controls_df = read_controls(controls_fn, OTUnames=NULL, areanames=NULL, tmpskip=0)


# Setup
prior_prob_presence = 0.01
areas = c("K", "O", "M", "H")
numareas = length(areas)
maxareas = length(areas)
states_list_0based_index =
rcpp_areas_list_to_states_list(areas=areas, maxareas=maxareas,
                               include_null_range=TRUE)
states_list_0based_index

mean_frequency=0.1
dp=1
fdp=0

tip_condlikes_of_data_on_each_state =
tiplikes_wDetectionModel(states_list_0based_index, numareas=numareas,
detects_df, controls_df, mean_frequency=mean_frequency, dp=dp, fdp=fdp,
null_range_gets_0_like=TRUE)

tip_condlikes_of_data_on_each_state



# To get denominator, just iterate over all the states
# Prior probability
prob_of_each_range = prob_of_states_from_prior_prob_areas(states_list_0based_index,
numareas=numareas,
prior_prob_presence=prior_prob_presence, null_range_gets_0_prob=TRUE,
normalize_probs=TRUE)

# Likelihoods of the data on each range
condlikes_of_data_on_each_range = tip_condlikes_of_data_on_each_state[1,]

posterior_probs = post_prob_states(prob_of_each_range,
                  condlikes_of_data_on_each_range)
posterior_probs

# Should sum to 1
sum(posterior_probs)

BioGeoBEARS documentation built on May 29, 2017, 8:36 p.m.