BP2D: Bayesian estimation using two dimensions Bernstein polynomial

Description Usage Arguments Value References See Also Examples

View source: R/BP2D.R

Description

This function runs Metropolis-Hasting algorithm which is given setting prior and data.This algorithm starts storing coefficients when it runs halfway,so we use second halves of coefficients compute Rhat to check convergence.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
BP2D(
  prior,
  ages,
  years,
  disease,
  population,
  Iterations = 2e+05,
  n_chain = 5,
  n_cluster = 1,
  nn = 2,
  interval = 100,
  RJC = 0.35,
  seed = TRUE,
  set = 1,
  double = 4
)

Arguments

prior

prior=(n0,alpha,L) where alpha is a Poisson parameter,n0 is upper bound of alpha L can be every number which is bigger than one.

ages

Range of ages.

years

Range of years.

disease

Disease matrix.

population

Population matrix.

Iterations

Iterations of chain.

n_chain

Number of Markov chain.

n_cluster

This parameter means number of cores, five cores is recommended.(default: n_cluster=1).

nn

The parameter nn is lower bound of alpha.

interval

Each hundreds save one coefficient.

RJC

Control parameter for transfer dimension.

seed

Set seed yes or not.

set

Choose seed.(defaults:set=1)

double

If R.hat >1.1 then double the iterations of times.

Value

This function will return Bayesian estimate of incidence,Stored parameters,posterior mean,posterior max and table.

Fhat

Bayesian estimate of incidence.

chain

Bayesian estimate of posterior p-value mean.

maxchain

Bayesian estimate of posterior p-value max.

store_coefficients

Two dimensional Bernstein coefficients.

output

When M-H algorithm ends,contruct the table which contains norm,mean of Fhat,maximum of Fhat,R.hat,iterations,P-value and elasped time.

References

Li-Chu Chien,Yuh-Jenn Wu,Chao A. Hsiung,Lu-Hai Wang,I-Shou Chang(2015).Smoothed Lexis Diagrams With Applications to Lung and Breast Cancer Trends in Taiwan,Journal of the American Statistical Association, Taylor & Francis Journals, vol. 110(511), pages 1000-1012, September.

See Also

Other Bayesain estimate: BP2D_coef(), BP2D_table()

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
# ---------------------------------------- #
library(BayesBP)
ages<-35:85
years<-1988:2007
prior<-c(10,5,2)
data(simulated_data_1)
disease<-simulated_data_1$disease
population<-simulated_data_1$population
result<-BP2D(prior,ages,years,disease,population)
# ---------------------------------------- #
# Bernstein basis
basis<-BPbasis(ages,years,10)
pdbasis1<-PD_BPbasis(ages,years,10,by = 1)
pdbasis2<-PD_BPbasis(ages,years,10,by = 2)
# Bernstein polynomial
coef<-result$store_coefficients$chain_1[[1]]
BPFhat(coef,ages,years,basis)
PD_BPFhat(coef,ages,years,pdbasis1,by = 1)
PD_BPFhat(coef,ages,years,pdbasis2,by = 2)
# Credible interval
Credible_interval(result)
PD_Credible_interval(result,by = 1)
PD_Credible_interval(result,by = 2)
# ---------------------------------------- #
# Given four prior set
ages<-35:85
years<-1988:2007
data(simulated_data_2)
disease<-simulated_data_2$disease
population<-simulated_data_2$population
p<-expand.grid(n0=c(10,20),alpha=c(5,10),LL=c(2,4))
prior_set<-p[p$n0==p$alpha*2,]
result_list<-paste0('result',1:nrow(prior_set))
for (i in seq_len(nrow(prior_set))) {
   prior<-prior_set[i,]
   assign(result_list[i],BP2D(prior,ages,years,disease,population))
   write.BP(get(result_list[i]),sprintf('%s.xlsx',result_list[i]))
}
tab<-BP2D_table(result_list)
write.BPtable(tab,'result_table.xlsx')
# ---------------------------------------- #

BayesBP documentation built on Aug. 28, 2020, 1:10 a.m.

Related to BP2D in BayesBP...