Title: | Bayesian Functional Linear Regression with Sparse Step Functions |
---|---|
Description: | A method for the Bayesian functional linear regression model (scalar-on-function), including two estimators of the coefficient function and an estimator of its support. A representation of the posterior distribution is also available. Grollemund P-M., Abraham C., Baragatti M., Pudlo P. (2019) <doi:10.1214/18-BA1095>. |
Authors: | Paul-Marie Grollemund [aut, cre], Isabelle Sanchez [ctr], Meili Baragatti [ctr] |
Maintainer: | Paul-Marie Grollemund <[email protected]> |
License: | GPL-3 |
Version: | 1.1.1 |
Built: | 2024-11-15 06:26:22 UTC |
Source: | CRAN |
Check if a number belong to a given interval.
value %between% interval
value %between% interval
value |
a numerical value. |
interval |
a numerical vector: (lower,upper). |
a logical value.
1 %between% c(0,2) 2 %between% c(0,2) 3 %between% c(0,2)
1 %between% c(0,2) 2 %between% c(0,2) 3 %between% c(0,2)
Model selection with BIC criterion.
BIC_model_choice(Ks, iter, data, verbose = T)
BIC_model_choice(Ks, iter, data, verbose = T)
Ks |
a numerical vector containing the K values. |
iter |
an integer, the number of iteration for each run of |
data |
a list containing required options to run the function
|
verbose |
write stuff if TRUE (optional). |
A numerical vector, the BIC values for the Bliss model for different K value.
param_sim <- list(Q=1,n=100,p=c(50),grids_lim=list(c(0,1))) data <- sim(param_sim,verbose=TRUE) iter = 1e2 Ks <- 1:5 res_BIC <- BIC_model_choice(Ks,iter,data) plot(res_BIC,xlab="K",ylab="BIC")
param_sim <- list(Q=1,n=100,p=c(50),grids_lim=list(c(0,1))) data <- sim(param_sim,verbose=TRUE) iter = 1e2 Ks <- 1:5 res_BIC <- BIC_model_choice(Ks,iter,data) plot(res_BIC,xlab="K",ylab="BIC")
A method for the Bayesian Functional Linear Regression model (functions-on-scalar), including two estimators of the coefficient function and an estimator of its support. A representation of the posterior distribution is also available.
Maintainer: Paul-Marie Grollemund [email protected]
Other contributors:
Isabelle Sanchez [email protected] [contractor]
Meili Baragatti [email protected] [contractor]
Useful links:
A Gibbs Sampler algorithm to sample the posterior distribution of the Bliss model.
Bliss_Gibbs_Sampler(data, param, verbose = FALSE)
Bliss_Gibbs_Sampler(data, param, verbose = FALSE)
data |
a list containing:
|
param |
a list containing:
|
verbose |
write stuff if TRUE (optional). |
a list containing :
a matrix, the trace of the Gibbs Sampler.
a list containing parameters used to run the function.
param_sim <- list(Q=1,n=25,p=50,grids_lim=list(c(0,1)),iter=2e2,K=2) data_sim <- sim(param_sim,verbose=FALSE) res_Bliss_Gibbs_Sampler <- Bliss_Gibbs_Sampler(data_sim,param_sim) theta_1 <- res_Bliss_Gibbs_Sampler$trace[1,] theta_1
param_sim <- list(Q=1,n=25,p=50,grids_lim=list(c(0,1)),iter=2e2,K=2) data_sim <- sim(param_sim,verbose=FALSE) res_Bliss_Gibbs_Sampler <- Bliss_Gibbs_Sampler(data_sim,param_sim) theta_1 <- res_Bliss_Gibbs_Sampler$trace[1,] theta_1
A Simulated Annealing algorithm to compute the Bliss estimate.
Bliss_Simulated_Annealing( beta_sample, posterior_sample, param, verbose_cpp = FALSE )
Bliss_Simulated_Annealing( beta_sample, posterior_sample, param, verbose_cpp = FALSE )
beta_sample |
a matrix. Each row is a coefficient function computed from the posterior sample. |
posterior_sample |
a list resulting from the |
param |
a list containing:
|
verbose_cpp |
Rcpp writes stuff if TRUE (optional). |
a list containing:
a numerical vector, corresponding to the Bliss estimate of the coefficient function.
a numerical vector, which is the posterior expectation of the coefficient function for each time points.
a matrix, the trace of the algorithm.
data(data1) data(param1) data(res_bliss1) param1$Q <- length(data1$x) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) posterior_sample <- res_bliss1$posterior_sample beta_sample <- compute_beta_sample(posterior_sample,param1) res_sann <- Bliss_Simulated_Annealing(beta_sample,posterior_sample,param1)
data(data1) data(param1) data(res_bliss1) param1$Q <- length(data1$x) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) posterior_sample <- res_bliss1$posterior_sample beta_sample <- compute_beta_sample(posterior_sample,param1) res_sann <- Bliss_Simulated_Annealing(beta_sample,posterior_sample,param1)
Define a Fourier basis to simulate functional covariate observations.
build_Fourier_basis(grid, dim, per = 2 * pi)
build_Fourier_basis(grid, dim, per = 2 * pi)
grid |
a numerical vector. |
dim |
a numerical value. It corresponds to |
per |
a numerical value which corresponds to the period of the sine and cosine functions. |
See the sim_x
function.
a matrix. Each row is an functional observation evaluated on the
grid
time points.
# See the function \code{sim_x}.
# See the function \code{sim_x}.
Compute a function (evaluated on a grid) on a given (finer) grid.
change_grid(fct, grid, new_grid)
change_grid(fct, grid, new_grid)
fct |
a numerical vector, the function to evaluate on the new grid. |
grid |
a numerical vector, the initial grid. |
new_grid |
a numerical vector, the new grid. |
a numerical vector, the approximation of the function on the new grid.
grid <- seq(0,1,l=1e1) new_grid <- seq(0,1,l=1e2) fct <- 3*grid^2 + sin(grid*2*pi) plot(grid,fct,type="o",lwd=2,cex=1.5) lines(new_grid,change_grid(fct,grid,new_grid),type="o",col="red",cex=0.8)
grid <- seq(0,1,l=1e1) new_grid <- seq(0,1,l=1e2) fct <- 3*grid^2 + sin(grid*2*pi) plot(grid,fct,type="o",lwd=2,cex=1.5) lines(new_grid,change_grid(fct,grid,new_grid),type="o",col="red",cex=0.8)
Compute a coefficient function for the Function Linear Regression model.
choose_beta(param)
choose_beta(param)
param |
a list containing:
|
Several shapes are available.
A numerical vector which corresponds to the coefficient function
at given times points (grid
).
### smooth param <- list(p=100,grid=seq(0,1,length=100),shape="smooth") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### random_smooth param <- list(p=100,grid=seq(0,1,length=100),shape="random_smooth") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### simple param <- list(p=100,grid=seq(0,1,length=100),shape="simple") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### simple_bis param <- list(p=100,grid=seq(0,1,length=100),shape="simple_bis") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### random_simple param <- list(p=100,grid=seq(0,1,length=100),shape="random_simple") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### sinusoid param <- list(p=100,grid=seq(0,1,length=100),shape="sinusoid") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### flat_sinusoid param <- list(p=100,grid=seq(0,1,length=100),shape="flat_sinusoid") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### sharp param <- list(p=100,grid=seq(0,1,length=100),shape="sharp") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l")
### smooth param <- list(p=100,grid=seq(0,1,length=100),shape="smooth") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### random_smooth param <- list(p=100,grid=seq(0,1,length=100),shape="random_smooth") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### simple param <- list(p=100,grid=seq(0,1,length=100),shape="simple") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### simple_bis param <- list(p=100,grid=seq(0,1,length=100),shape="simple_bis") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### random_simple param <- list(p=100,grid=seq(0,1,length=100),shape="random_simple") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="s") ### sinusoid param <- list(p=100,grid=seq(0,1,length=100),shape="sinusoid") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### flat_sinusoid param <- list(p=100,grid=seq(0,1,length=100),shape="flat_sinusoid") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l") ### sharp param <- list(p=100,grid=seq(0,1,length=100),shape="sharp") beta_function <- choose_beta(param) plot(param$grid,beta_function,type="l")
Compute the posterior density of the coefficient function.
compute_beta_posterior_density(beta_sample, param)
compute_beta_posterior_density(beta_sample, param)
beta_sample |
a matrix. Each row is a coefficient function computed from the posterior sample. |
param |
a list containing:
|
The posterior densities correponds to approximations of the marginal
posterior distribitions (of beta(t) for each t).
The sample is thinned in order to reduce the correlation and the
computational time of the function kde2d
.
An approximation of the posterior density on a two-dimensional grid
(corresponds to the result of the kde2d
function).
library(RColorBrewer) data(data1) data(param1) data(res_bliss1) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) param1$Q <- length(data1$x) density_estimate <- compute_beta_posterior_density(res_bliss1$beta_sample,param1)
library(RColorBrewer) data(data1) data(param1) data(res_bliss1) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) param1$Q <- length(data1$x) density_estimate <- compute_beta_posterior_density(res_bliss1$beta_sample,param1)
Compute the posterior coefficient function from the posterior sample.
compute_beta_sample(posterior_sample, param)
compute_beta_sample(posterior_sample, param)
posterior_sample |
a list provided by the function |
param |
a list containing:
|
a matrix containing the coefficient function posterior sample.
data(data1) data(param1) data(res_bliss1) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) param1$Q <- length(data1$x) beta_sample <- compute_beta_sample(posterior_sample=res_bliss1$posterior_sample, param=param1)
data(data1) data(param1) data(res_bliss1) param1$grids <- data1$grids param1$p <- sapply(data1$grids,length) param1$Q <- length(data1$x) beta_sample <- compute_beta_sample(posterior_sample=res_bliss1$posterior_sample, param=param1)
Compute summaries of Gibbs Sampler chains.
compute_chains_info(chain, param)
compute_chains_info(chain, param)
chain |
a list given by the |
param |
a list containing:
|
Return a list containing the estimates of mu
and sigma_sq
, the
Smooth estimate and the chain autocorrelation for mu
, sigma_sq
and beta
.
a=1
a=1
Compute a (Gaussian) random walk.
compute_random_walk(n, p, mu, sigma, start = rep(0, n))
compute_random_walk(n, p, mu, sigma, start = rep(0, n))
n |
an integer, the number of random walks. |
p |
an integer, the length of the random walks. |
mu |
a numerical vector, the mean of the random walks. |
sigma |
a numerical value which is the standard deviation of the gaussian distribution used to compute the random walks. |
start |
a numerical vector (optional) which is the initial value of the random walks. |
See the sim_x
function.
a matrix where each row is a random walk.
# see the sim_x() function.
# see the sim_x() function.
Compute a starting point for the Simulated Annealing algorithm.
compute_starting_point_sann(beta_expe)
compute_starting_point_sann(beta_expe)
beta_expe |
a numerical vector, the expectation of the coefficient function posterior sample. |
a matrix with 3 columns : "m", "l" and "b". The two first columns define the begin and the end of the intervals and the third gives the mean values of each interval.
data(res_bliss1) mystart<-compute_starting_point_sann(apply(res_bliss1$beta_sample[[1]],2,mean))
data(res_bliss1) mystart<-compute_starting_point_sann(apply(res_bliss1$beta_sample[[1]],2,mean))
Compute an autocorrelation matrix.
corr_matrix(diagonal, ksi)
corr_matrix(diagonal, ksi)
diagonal |
a numerical vector corresponding to the diagonal. |
ksi |
a numerical value, related to the correlation. |
a symmetric matrix.
### Test 1 : weak autocorrelation ksi <- 1 diagVar <- abs(rnorm(100,50,5)) Sigma <- corr_matrix(diagVar,ksi^2) persp(Sigma) ### Test 2 : strong autocorrelation ksi <- 0.2 diagVar <- abs(rnorm(100,50,5)) Sigma <- corr_matrix(diagVar,ksi^2) persp(Sigma)
### Test 1 : weak autocorrelation ksi <- 1 diagVar <- abs(rnorm(100,50,5)) Sigma <- corr_matrix(diagVar,ksi^2) persp(Sigma) ### Test 2 : strong autocorrelation ksi <- 0.2 diagVar <- abs(rnorm(100,50,5)) Sigma <- corr_matrix(diagVar,ksi^2) persp(Sigma)
A data object for bliss model
data1
data1
a list of data
y coordinate
x coordinate
the coefficient function used to generate the data
the grid of the observation times
Determine for which intervals a function is nonnull.
determine_intervals(beta_fct)
determine_intervals(beta_fct)
beta_fct |
a numerical vector. |
a matrix with 3 columns : "begin", "end" and "value". The two first columns define the begin and the end of the intervals and the third gives the mean values of each interval.
data(data1) data(param1) # result of res_bliss1<-fit_Bliss(data=data1,param=param1) data(res_bliss1) intervals <- determine_intervals(res_bliss1$Bliss_estimate[[1]]) plot(data1$grids[[1]],res_bliss1$Bliss_estimate[[1]],type="s") for(k in 1:nrow(intervals)){ segments(data1$grids[[1]][intervals[k,1]],intervals[k,3], data1$grids[[1]][intervals[k,2]],intervals[k,3],col=2,lwd=4) }
data(data1) data(param1) # result of res_bliss1<-fit_Bliss(data=data1,param=param1) data(res_bliss1) intervals <- determine_intervals(res_bliss1$Bliss_estimate[[1]]) plot(data1$grids[[1]],res_bliss1$Bliss_estimate[[1]],type="s") for(k in 1:nrow(intervals)){ segments(data1$grids[[1]][intervals[k,1]],intervals[k,3], data1$grids[[1]][intervals[k,2]],intervals[k,3],col=2,lwd=4) }
Determine if it is required to reduce the size of the grid time points for each functional covariate.
do_need_to_reduce(param)
do_need_to_reduce(param)
param |
a list containing p_threshold the maximum number of time points and p the actual number of time points for each functional covariate. |
a boolean value.
data(param1) param1$p <- sapply(data1$grids,length) do_need_to_reduce(param1)
data(param1) param1$p <- sapply(data1$grids,length) do_need_to_reduce(param1)
Compute (non-normalized) posterior densities for a given parameter set.
dposterior(posterior_sample, data, theta = NULL)
dposterior(posterior_sample, data, theta = NULL)
posterior_sample |
a list given by the |
data |
a list containing
|
theta |
a matrix or a vector which contains the parameter set. |
If the theta
is NULL, the posterior density is computed from
the MCMC sample given in the posterior_sample
.
Return the (log) posterior density, the (log) likelihood and the (log) prior density for the given parameter set.
data(data1) data(param1) # result of res_bliss1<-fit_Bliss(data=data1,param=param1) data(res_bliss1) # Compute the posterior density of the MCMC sample : res_poste <- dposterior(res_bliss1$posterior_sample,data1)
data(data1) data(param1) # result of res_bliss1<-fit_Bliss(data=data1,param=param1) data(res_bliss1) # Compute the posterior density of the MCMC sample : res_poste <- dposterior(res_bliss1$posterior_sample,data1)
Fit the Bayesian Functional Linear Regression model (with Q functional covariates).
fit_Bliss( data, param, sann = TRUE, compute_density = TRUE, support_estimate = TRUE, sann_trace = FALSE, verbose = TRUE )
fit_Bliss( data, param, sann = TRUE, compute_density = TRUE, support_estimate = TRUE, sann_trace = FALSE, verbose = TRUE )
data |
a list containing:
|
param |
a list containing:
|
sann |
a logical value. If TRUE, the Bliss estimate is computed with a Simulated Annealing Algorithm. (optional) |
compute_density |
a logical value. If TRUE, the posterior density of the coefficient function is computed. (optional) |
support_estimate |
a logical value. If TRUE, the estimate of the coefficient function support is computed. (optional) |
sann_trace |
a logical value. If TRUE, the trace of the Simulated Annealing algorithm is included into the result object. (optional) |
verbose |
write stuff if TRUE (optional). |
return a list containing:
a list of Q numerical vector. Each vector is the function alpha(t) associated to a functional covariate. For each t, alpha(t) is the posterior probabilities of the event "the support covers t".
a list of Q items. Each item contains a list
containing information to plot the posterior density of the
coefficient function with the image
function.
grid_t
a numerical vector: the x-axis.
grid_beta_t
a numerical vector: the y-axis.
density
a matrix: the z values.
new_beta_sample
a matrix: beta sample used to compute the posterior densities.
a list of Q matrices. The qth matrix is a posterior sample of the qth functional covariates.
a list of numerical vectors corresponding to the Bliss estimates of each functional covariates.
a list containing the data.
a list of information about the posterior sample: the trace matrix of the Gibbs sampler, a list of Gibbs sampler parameters and the posterior densities.
a list of support estimates of each functional covariate.
another version of the support estimates.
a list of Q matrices which are the trace of the Simulated Annealing algorithm.
# see the vignette BlissIntro.
# see the vignette BlissIntro.
Plot an approximation of the posterior density.
image_Bliss(beta_posterior_density, param = list(), q = 1, to_print = TRUE)
image_Bliss(beta_posterior_density, param = list(), q = 1, to_print = TRUE)
beta_posterior_density |
a list. The result of the function
|
param |
an optional list containing arguments: col_low, col_mid, col_high, ylim, xlab, ylab, title. |
q |
an integer (optional), the index of the functional covariate to plot. |
to_print |
display the plot if TRUE. |
data(data1) data(param1) data(res_bliss1) image_Bliss(res_bliss1$beta_posterior_density,param1,q=1)
data(data1) data(param1) data(res_bliss1) image_Bliss(res_bliss1$beta_posterior_density,param1,q=1)
Trapezoidal rule to approximate an integral.
integrate_trapeze(x, y)
integrate_trapeze(x, y)
x |
a numerical vector, the discretization of the domain. |
y |
a numerical value, the discretization of the function to integrate. |
a numerical value, the approximation.
x <- seq(0,1,le=1e2) integrate_trapeze(x,x^2) integrate_trapeze(data1$grids[[1]],t(data1$x[[1]]))
x <- seq(0,1,le=1e2) integrate_trapeze(x,x^2) integrate_trapeze(data1$grids[[1]],t(data1$x[[1]]))
Provide a graphical representation of the functional data with a focus on the detected periods with the Bliss method.
interpretation_plot(data, Bliss_estimate, q = 1, centered = FALSE, cols = NULL)
interpretation_plot(data, Bliss_estimate, q = 1, centered = FALSE, cols = NULL)
data |
a list containing:
|
Bliss_estimate |
a numerical vector, the Bliss estimate. |
q |
an integer (optional), the index of the functional covariate to plot. |
centered |
a logical value (optional), If TRUE, the functional data are centered. |
cols |
a numerical vector of colours (optional). |
data(data1) data(param1) # result of res_bliss1 <- fit_Bliss(data=data1,param=param1,verbose=TRUE) data(res_bliss1) interpretation_plot(data=data1,Bliss_estimate=res_bliss1$Bliss_estimate,q=1) interpretation_plot(data=data1,Bliss_estimate=res_bliss1$Bliss_estimate,q=1,centered=TRUE)
data(data1) data(param1) # result of res_bliss1 <- fit_Bliss(data=data1,param=param1,verbose=TRUE) data(res_bliss1) interpretation_plot(data=data1,Bliss_estimate=res_bliss1$Bliss_estimate,q=1) interpretation_plot(data=data1,Bliss_estimate=res_bliss1$Bliss_estimate,q=1,centered=TRUE)
Add a line to a plot obtained with image_Bliss
.
lines_bliss(x, y, col = "black", lty = "solid")
lines_bliss(x, y, col = "black", lty = "solid")
x |
the coordinates of points in the plot. |
y |
the y coordinates of points in the plot. |
col |
a color. |
lty |
option corresponding to "linetype" of |
data(data1) data(param1) data(res_bliss1) image_Bliss(res_bliss1$beta_posterior_density,param1,q=1) + lines_bliss(res_bliss1$data$grids[[1]],res_bliss1$smooth_estimate[[1]])+ lines_bliss(res_bliss1$data$grids[[1]],res_bliss1$Bliss_estimate[[1]],col="purple")
data(data1) data(param1) data(res_bliss1) image_Bliss(res_bliss1$beta_posterior_density,param1,q=1) + lines_bliss(res_bliss1$data$grids[[1]],res_bliss1$smooth_estimate[[1]])+ lines_bliss(res_bliss1$data$grids[[1]],res_bliss1$Bliss_estimate[[1]],col="purple")
A list of param for bliss model
param1
param1
a list of param for bliss model
the number of functional covariates
the sample size
the number of observation times
the shapes of the coefficient functions
the range of the observation times
the grids of the observation times
the number of intervals for the coefficient function
Probability function of a discretized Exponentiel distribution.
pdexp(a, l_values)
pdexp(a, l_values)
a |
a positive value, the mean of the Exponential prior. |
l_values |
a numerical value, the discrete support of the parameter l. |
a numerical vector, which is the prability function on l_values
.
pdexp(10,seq(0,1,1)) x <- seq(0,10,le=1e3) plot(x,dexp(x,0.5),lty=2,type="l") lines(pdexp(0.5,1:10),type="p")
pdexp(10,seq(0,1,1)) x <- seq(0,10,le=1e3) plot(x,dexp(x,0.5),lty=2,type="l") lines(pdexp(0.5,1:10),type="p")
Compute the post treatment values.
post_treatment_bliss(posterior_sample, param, data)
post_treatment_bliss(posterior_sample, param, data)
posterior_sample |
a list provided by the function |
param |
a list containing:
|
data |
a list containing required options to run the function
|
A list of important post treatment value: BIC, the maximum of the log likelihood and the numbre of parameters.
data(data1) data(param1) data(res_bliss1) post_treatment_bliss(res_bliss1$posterior_sample,param1,data1)
data(data1) data(param1) data(res_bliss1) post_treatment_bliss(res_bliss1$posterior_sample,param1,data1)
Compute predictions.
predict_bliss(x, grids, burnin, posterior_sample, Smooth_estimate)
predict_bliss(x, grids, burnin, posterior_sample, Smooth_estimate)
x |
a list containing the design matrices related to the functional
covariates. Must be similar to the result of the function |
grids |
a list of numerical vectors, the qth vector is the grid of time points for the qth functional covariate. |
burnin |
an integer (optional), the number of iteration to drop from the posterior sample. |
posterior_sample |
a list provided by the function |
Smooth_estimate |
one of the objects resulting from |
A vector of predictions for each individual data x
.
data(data1) data(param1) data(res_bliss1) predict_bliss(data1$x,data1$grids,50,res_bliss1$posterior_sample,res_bliss1$smooth_estimate)
data(data1) data(param1) data(res_bliss1) predict_bliss(data1$x,data1$grids,50,res_bliss1$posterior_sample,res_bliss1$smooth_estimate)
Compute the distribution of the predictions.
predict_bliss_distribution(x, grids, burnin, posterior_sample, beta_sample)
predict_bliss_distribution(x, grids, burnin, posterior_sample, beta_sample)
x |
a list containing the design matrices related to the functional
covariates. Must be similar to the result of the function |
grids |
a list of numerical vectors, the qth vector is the grid of time points for the qth functional covariate. |
burnin |
an integer (optional), the number of iteration to drop from the posterior sample. |
posterior_sample |
a list provided by the function |
beta_sample |
a list provided by the function |
A matrix containing predictions for each individual data x
.
data(data1) data(param1) data(res_bliss1) predict_bliss_distribution(data1$x,data1$grids,50,res_bliss1$posterior_sample, res_bliss1$beta_sample)
data(data1) data(param1) data(res_bliss1) predict_bliss_distribution(data1$x,data1$grids,50,res_bliss1$posterior_sample, res_bliss1$beta_sample)
Print a bliss Object
printbliss(x, ...)
printbliss(x, ...)
x |
input bliss Object |
... |
further arguments passed to or from other methods |
# See fit_Bliss() function
# See fit_Bliss() function
Reduce the number of time points.
reduce_x(data, param)
reduce_x(data, param)
data |
similar to |
param |
a list containing values |
a numerical value, the approximation.
param <- list(Q=1,n=10,p=c(150),grids_lim=list(c(0,1))) data <- sim(param) data(param1) param1$n <- nrow(data$x[[1]]) param1$p <- sapply(data$grids,length) param1$Q <- length(data$x) data <- reduce_x(data,param1)
param <- list(Q=1,n=10,p=c(150),grids_lim=list(c(0,1))) data <- sim(param) data(param1) param1$n <- nrow(data$x[[1]]) param1$p <- sapply(data$grids,length) param1$Q <- length(data$x) data <- reduce_x(data,param1)
A result of the BliSS method
res_bliss1
res_bliss1
a Bliss object (list)
a list of Q numerical vector. Each vector is the function alpha(t) associated to a functional covariate. For each t, alpha(t) is the posterior probabilities of the event "the support covers t".
a list of Q items. Each item contains a list
containing information to plot the posterior density of the
coefficient function with the image
function.
grid_t
a numerical vector: the x-axis.
grid_beta_t
a numerical vector: the y-axis.
density
a matrix: the z values.
new_beta_sample
a matrix: beta sample used to compute the posterior densities.
a list of Q matrices. The qth matrix is a posterior sample of the qth functional covariates.
a list of numerical vectors corresponding to the Bliss estimates of each functional covariates.
see the description of the object data1
.
a list containing (for each chain) the result of the
Bliss_Gibbs_Sampler
function.
a list containing the Smooth estimates of the coefficient functions.
a list containing the estimations of the support.
a list containing the estimation of the support.
a list containing (for each chain) the trace of the Simulated Annealing algorithm.
Compute a sigmoid function.
sigmoid(x, asym = 1, v = 1)
sigmoid(x, asym = 1, v = 1)
x |
a numerical vector, time points. |
asym |
a numerical value (optional), the asymptote of the sigmoid function. |
v |
a numerical value (optional), related to the slope at the origin. |
see the function sim_x
.
a numerical vector.
## Test 1 : x <- seq(-7,7,0.1) y <- sigmoid(x) plot(x,y,type="l",main="Sigmoid function") ## Test 2 : x <- seq(-7,7,0.1) y <- sigmoid(x) y2 <- sigmoid(x,asym=0.5) y3 <- sigmoid(x,v = 5) plot(x,y,type="l",main="Other sigmoid functions") lines(x,y2,col=2) lines(x,y3,col=3)
## Test 1 : x <- seq(-7,7,0.1) y <- sigmoid(x) plot(x,y,type="l",main="Sigmoid function") ## Test 2 : x <- seq(-7,7,0.1) y <- sigmoid(x) y2 <- sigmoid(x,asym=0.5) y3 <- sigmoid(x,v = 5) plot(x,y,type="l",main="Other sigmoid functions") lines(x,y2,col=2) lines(x,y3,col=3)
Compute a sharp sigmoid function.
sigmoid_sharp(x, loc = 0, ...)
sigmoid_sharp(x, loc = 0, ...)
x |
a numerical vector, time points. |
loc |
a numerical value (optional), the time of the sharp. |
... |
Arguments (optional) for the function sigmoid. |
see the function sim_x
.
a numerical vector.
## Test 1 : x <- seq(-7,7,0.1) y <- sigmoid_sharp(x) plot(x,y,type="l",main="Sharp sigmoid") ## Test 2 : x <- seq(-7,7,0.1) y <- sigmoid_sharp(x,loc=3) y2 <- sigmoid_sharp(x,loc=3,asym=0.5) y3 <- sigmoid_sharp(x,loc=3,v = 5) plot(x,y,type="l",main="Other sharp sigmoids") lines(x,y2,col=2) lines(x,y3,col=3)
## Test 1 : x <- seq(-7,7,0.1) y <- sigmoid_sharp(x) plot(x,y,type="l",main="Sharp sigmoid") ## Test 2 : x <- seq(-7,7,0.1) y <- sigmoid_sharp(x,loc=3) y2 <- sigmoid_sharp(x,loc=3,asym=0.5) y3 <- sigmoid_sharp(x,loc=3,v = 5) plot(x,y,type="l",main="Other sharp sigmoids") lines(x,y2,col=2) lines(x,y3,col=3)
Simulate a dataset for the Function Linear Regression model.
sim(param, verbose = FALSE)
sim(param, verbose = FALSE)
param |
a list containing:
|
verbose |
write stuff if TRUE. |
a list containing:
an integer, the number of functional covariates.
a numerical vector, the outcome observations.
a list of matrices, the qth matrix contains the observations of the
qth functional covariate at time points given by grids
.
a list of numerical vectors, the qth vector is the grid of time points for the qth functional covariate.
a list of numerical vectors, the qth vector is the 'true' coefficient
function associated to the qth covariate on a grid of time points
given with grids
.
library(RColorBrewer) param <- list(Q=2,n=25,p=c(50,50),grids_lim=list(c(0,1),c(-1,2))) data <- sim(param) data$y cols <- colorRampPalette(brewer.pal(9,"YlOrRd"))(10) q=2 matplot(data$grids[[q]],t(data$x[[q]]),type="l",lty=1,col=cols) plot(data$grids[[q]],data$betas[[q]],type="l") abline(h=0,lty=2,col="gray")
library(RColorBrewer) param <- list(Q=2,n=25,p=c(50,50),grids_lim=list(c(0,1),c(-1,2))) data <- sim(param) data$y cols <- colorRampPalette(brewer.pal(9,"YlOrRd"))(10) q=2 matplot(data$grids[[q]],t(data$x[[q]]),type="l",lty=1,col=cols) plot(data$grids[[q]],data$betas[[q]],type="l") abline(h=0,lty=2,col="gray")
Simulate functional covariate observations.
sim_x(param)
sim_x(param)
param |
a list containing :
|
Several shape are available for the observations: "Fourier", "Fourier2", "random_walk", "random_sharp", "uniform", "gaussian", "mvgauss", "mvgauss_different_scale", "mvgauss_different_scale2", "mvgauss_different_scale3" and "mvgauss_different_scale4".
a matrix which contains the functional covariate observations at time
points given by grid
.
library(RColorBrewer) ### uniform param <- list(n=15,p=100,grid=seq(0,1,length=100),x_type="uniform") x <- sim_x(param) cols <- colorRampPalette(brewer.pal(9,"YlOrRd"))(15) matplot(param$grid,t(x),type="l",lty=1,col=cols)
library(RColorBrewer) ### uniform param <- list(n=15,p=100,grid=seq(0,1,length=100),x_type="uniform") x <- sim_x(param) cols <- colorRampPalette(brewer.pal(9,"YlOrRd"))(15) matplot(param$grid,t(x),type="l",lty=1,col=cols)
Compute the support estimate.
support_estimation(beta_sample, param)
support_estimation(beta_sample, param)
beta_sample |
the result of the function |
param |
a list containing the value |
a list containing:
a numerical vector. The approximated posterior probabilities
that the coefficient function support covers t
for each time
points t
.
a numerical vector, the support estimate.
a numerical vector, another version of the support estimate.
data(data1) data(param1) data(res_bliss1) param1$Q <- length(data1$x) res_support <- support_estimation(res_bliss1$beta_sample,param1)
data(data1) data(param1) data(res_bliss1) param1$Q <- length(data1$x) res_support <- support_estimation(res_bliss1$beta_sample,param1)