Title: | Bayesian Estimation using Bernstein Polynomial Fits Rate Matrix |
---|---|
Description: | Smoothed lexis diagrams with Bayesian method specifically tailored to cancer incidence data. Providing to calculating slope and constructing credible interval. LC Chien et al. (2015) <doi:10.1080/01621459.2015.1042106>. LH Chien et al. (2017) <doi:10.1002/cam4.1102>. |
Authors: | Li-Syuan Hong [aut, cre] |
Maintainer: | Li-Syuan Hong <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1 |
Built: | 2024-12-09 06:52:59 UTC |
Source: | CRAN |
Binomial function
bin(n, i, x)
bin(n, i, x)
n |
Integer. |
i |
Integer(i < n). |
x |
Numeric(0<= x <=1). |
bin(5,3,.5)
bin(5,3,.5)
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.
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 )
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 )
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. |
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. |
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.
Other Bayesain estimate:
BP2D_coef()
,
BP2D_table()
# ---------------------------------------- # 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') # ---------------------------------------- #
# ---------------------------------------- # 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') # ---------------------------------------- #
This function will return coefficient and length of each set of coefficeint.
BP2D_coef(result)
BP2D_coef(result)
result |
This is output of BP2D. |
Coefficients table.
Other Bayesain estimate:
BP2D_table()
,
BP2D()
If you give more groups of prior,you can use this function to get the table and T criterion.
BP2D_table(results_list)
BP2D_table(results_list)
results_list |
A vector of characters. |
Table and criterion T.
Other Bayesain estimate:
BP2D_coef()
,
BP2D()
This function build two dimensional Bernstein polynomial basis.
BPbasis(ages, years, n0, N = 1)
BPbasis(ages, years, n0, N = 1)
ages |
Range of ages. |
years |
Range of years. |
n0 |
Upper bound of possion random variable. |
N |
Lower bound of possion random variable. |
Bernstein basis.
Other Bernstein basis:
PD_BPbasis()
ages <- 35:85 years <- 1988:2007 list.basis <- BPbasis(ages,years,10) list.basis
ages <- 35:85 years <- 1988:2007 list.basis <- BPbasis(ages,years,10) list.basis
Given Bernstein polynomial coeffients to compute Fhat.
BPFhat(coef, ages, years, basis)
BPFhat(coef, ages, years, basis)
coef |
Bernstein polynomial coefficients. |
ages |
Range of ages. |
years |
Range of years. |
basis |
Bernstein polynomial basis. |
This function return outer Bernstein polynomial using coefficients.
Other outer Bernstein polynomial:
PD_BPFhat()
coef <- runif(9) ages <- 35:85 years <- 1988:2007 list.basis <- BPbasis(ages,years,10) BPFhat(coef,ages,years,list.basis)
coef <- runif(9) ages <- 35:85 years <- 1988:2007 list.basis <- BPbasis(ages,years,10) BPFhat(coef,ages,years,list.basis)
Builing two dimensional Bernstein polynomial credible interval.
Credible_interval(result, n_cluster = 1, alpha = 0.05)
Credible_interval(result, n_cluster = 1, alpha = 0.05)
result |
This is output of BP2D. |
n_cluster |
Muticores is remmended.(default:n_cluster=1) |
alpha |
Level of significance. |
Bayesian credible interval with level of significance.
L.H. Chien, T.J. Tseng, C.H. Chen, H.F. Jiang, F.Y. Tsai, T.W. Liu, C.A. Hsiung, I.S. Chang Comparison of annual percentage change in breast cancer incidence rate between Taiwan and the United States-A smoothed Lexis diagram approach.
Other Credible interval:
PD_Credible_interval()
Generated data
gen_data(ages, years, FT, M)
gen_data(ages, years, FT, M)
ages |
Ages. |
years |
Years. |
FT |
Rate function. |
M |
Population function. |
Risky population function
M(x, y)
M(x, y)
x |
Numeric. |
y |
Numeric. |
This function build two dimensional Bernstein polynomial basis.
PD_BPbasis(ages, years, n0, N = 1, by = 1)
PD_BPbasis(ages, years, n0, N = 1, by = 1)
ages |
Range of ages. |
years |
Range of years. |
n0 |
Upper bound of possion random variable. |
N |
Lower bound of possion random variable. |
by |
1: partial differential by ages; 2: partial differential by years. |
Partial differential Bernstein basis.
Other Bernstein basis:
BPbasis()
ages <- 35:85 years <- 1988:2007 pdbasis <- PD_BPbasis(ages,years,10,by = 1) pdbasis
ages <- 35:85 years <- 1988:2007 pdbasis <- PD_BPbasis(ages,years,10,by = 1) pdbasis
Given Bernstein polynomial coeffients to compute Fhat.
PD_BPFhat(coef, ages, years, pdbasis, by = 1)
PD_BPFhat(coef, ages, years, pdbasis, by = 1)
coef |
Bernstein polynomial coefficients. |
ages |
Range of ages. |
years |
Range of years. |
pdbasis |
Partial differential Bernstein polynomial basis. |
by |
1: partial differential by ages; 2: partial differential by years. |
Partial differential Bernstein polynomial given coefficients.
Other outer Bernstein polynomial:
BPFhat()
coef <- runif(9) ages <- 35:85 years <- 1988:2007 pdbasis <- PD_BPbasis(ages,years,10,N=1,by=1) PD_BPFhat(coef,ages,years,pdbasis,by=1)
coef <- runif(9) ages <- 35:85 years <- 1988:2007 pdbasis <- PD_BPbasis(ages,years,10,N=1,by=1) PD_BPFhat(coef,ages,years,pdbasis,by=1)
Builing two dimensional Bernstein polynomial credible interval.
PD_Credible_interval(result, n_cluster = 1, alpha = 0.05, by = 1)
PD_Credible_interval(result, n_cluster = 1, alpha = 0.05, by = 1)
result |
This is output of BP2D. |
n_cluster |
Muticores is remmended.(default:n_cluster=1) |
alpha |
Level of significance. |
by |
1: partial differential by ages; 2: partial differential by years. |
Bayesian credible interval with level of significance.
L.H. Chien, T.J. Tseng, C.H. Chen, H.F. Jiang, F.Y. Tsai, T.W. Liu, C.A. Hsiung, I.S. Chang Comparison of annual percentage change in breast cancer incidence rate between Taiwan and the United States-A smoothed Lexis diagram approach.
Other Credible interval:
Credible_interval()
Check Markov chains for convergence.
Rhat(M, burn.in = 0.5)
Rhat(M, burn.in = 0.5)
M |
An n x m numeric matrix of Markov Chains. |
burn.in |
The default value 0.5 means that the second halves of chains will be used to compute. |
Gelman Rubin statistics.
Gelman A.,Carlin J.B.,Stern H.S.,and Rubin D.B.(2004),Bayesian Data Analysis,Boca Raton,FL:Chapman&Hall/CRC.
Scale to [0,1]
scale_to_01(x)
scale_to_01(x)
x |
Vector. |
scale_to_01(35:85) (35:85-35)/(85-35) scale_to_01(runif(10))
scale_to_01(35:85) (35:85-35)/(85-35) scale_to_01(runif(10))
Given rate function 1 generated data.
data(simulated_data_1)
data(simulated_data_1)
list of matrix
ages <- 35:85 years <- 1988:2007 FT1 <- function(x,y){0.00148*sin(0.5*pi*x*y)+0.00002} simulated_data_1 <- gen_data(ages,years,FT1,M)
ages <- 35:85 years <- 1988:2007 FT1 <- function(x,y){0.00148*sin(0.5*pi*x*y)+0.00002} simulated_data_1 <- gen_data(ages,years,FT1,M)
Given rate function 2 generated data.
data(simulated_data_2)
data(simulated_data_2)
list of matrix
ages <- 35:85 years <- 1988:2007 FT2 <- function(x,y){0.00148*sin(0.5*pi*x*(y+0.2))+0.00002} simulated_data_2 <- gen_data(ages,years,FT2,M)
ages <- 35:85 years <- 1988:2007 FT2 <- function(x,y){0.00148*sin(0.5*pi*x*(y+0.2))+0.00002} simulated_data_2 <- gen_data(ages,years,FT2,M)
This function will write result of BP2D to xlsx file.
write.BP(writedata, filename)
write.BP(writedata, filename)
writedata |
result of BP2D(character or list). |
filename |
xlsx file name. |
If your environment has some result of BP2D,then you can use this function to store BPTable.
write.BPtable(BPtable, filename)
write.BPtable(BPtable, filename)
BPtable |
output of BP2D_table. |
filename |
xlsx file name. |