` library(bliss)`

This vignette describes step by step how to use the BLiSS method. Below, you can find the following implemented features:

- Simulate data to test the BLiSS model
- Obtain a sample of the posterior distribution with a Gibbs Sampler
- Plot the posterior distribution of the coefficient function and the posterior distribution of the support
- Compute the different Bayesian estimators

In order to simulate a proper dataset for Bliss application, some characteristics must be specified:

- \(n\) (the number of observations),
- \(p\) (number of instant of measure),
- beta\(\_\)types (the shape of the coefficient function), and
- grids\(\_\)lim, a 2-vector (to define the domain of curves \(x_{i}(.)\)).

Based on these parameters, data can be simulated (curves \(x_{i}(.)\) and real values \(y_{i}\)) from the functional linear
regression model by using the *sim* function, as suggested in the
following chunck.

```
set.seed(1)
param <- list( # define the "param" to simulate data
Q=1, # the number of functional covariate
n=50, # n is the sample size and p is the
p=c(20), # number of time observations of the curves
beta_types=c("smooth"), # define the shape of the "true" coefficient function
grids_lim=list(c(0,1))) # Give the beginning and the end of the observation's domain of the functions.
data <- sim(param) # Simulate the data
```

In order to apply the Bliss method, the main function to use is
*fit\(\_\)Bliss*. This function
provides the following outputs:

- a posterior sample of the Bliss model,
- an approximation of the posterior distribution of the coefficient function,
- a piecewise constant estimate (stepfunction) of the coefficient function, which is computed thanks to an optimization algorithm,
- an estimation of the support, which shoulb be useful if your purpose is to detect periods for which the functional coviarate has an (linear) impact on the dependent scalar variable,
- the posterior densities of the posterior sample, which should be used to compute model choice criterion.

An important required argument of the previous function is
**param**, which is a list containing:

**iter**, the number of iterations for the Gibbs algorithm,**burnin**the number of iteration to drop at the beginning of the Gibbs Sampler,**K**, hyperparameter \(K\) of the Bliss model,**grids**, the grid of instant for which the curves \(x_{i}(.)\) are measured,**prior\(\_\)beta**, an argument specifying a prior distribution of the slope coefficient \(\beta\), (only the**Ridge\(\_\)Zellner**case is considered in this vignette),- and
**phi\(\_\)l**, an argument specifying a prior distribution for \(\ell\) the half-width of the intervals (only the**Gamma`**case is considered in this vignette),

Find below, an example of use of this function and a sketch of the structure of the returned object.

```
param <- list( # define the required values of the Bliss method.
iter=5e2, # The number of iteration of the main numerical algorithm of Bliss.
burnin=2e2, # The number of burnin iteration for the Gibbs Sampler
K=c(3)) # The number of intervals of the beta
res_bliss<-fit_Bliss(data=data,param=param)
#> ===========================================================
#> - Pretreatment.
#> - Model fiting.
#> Gibbs Sampler: Sample from the posterior distribution.
#> Initialization.
#> Determine the starting point.
#> Start the Gibbs Sampler loop.
#> Compute beta functions related to the posterior sample.
#> - Derive estimates.
#> Simulated Annealing (to get the Bliss and smooth estimates):
#> Functional Dimension 1/1
Functional Dimension 1/1 Repeat 1/5
Functional
#> Dimension 1/1 Repeat 2/5
Functional Dimension 1/1 Repeat 3/5
Functional
#> Dimension 1/1 Repeat 4/5
Functional Dimension 1/1 Repeat 5/5
#>
#> Compute the approximation of the posterior distribution.
#> Support estimation.
#> - Posterior quantities.
#> Compute the (log) densities of the posterior sample.
#> Fitting posterior y values.
#> Usual quantities.
#> ===========================================================
#> nb_param loglik BIC MSE
#> 11.0000000 12.8003098 17.4316334 0.2930481
#> ===========================================================
#> * Useful fields
#> $Bliss_estime, $smooth_estimate, $support_estimate, $alpha,
#> $beta_posterior_density, $posterior_sample, $beta_sample
#> * Useful post-treatment functions
#> image_Bliss(), interpretation_plot()
# Structure of a Bliss object
# str(res_bliss)
```

This section presents how to obtain main graphical results (posterior quantities) derived from the Bliss method.

Considering Functional Linear Regression model (FLR), and the
specific *scalar-on-function* case, the major model parameter to
infer is the coefficient function \(\beta(.)\). The following chunck shows how
to plot the posterior distribution of the coefficient function:

```
library(ggplot2)
image_Bliss(res_bliss$beta_posterior_density,param,q=1)
```

Additionnaly to this plot, one could usually want to display a point
estimate of the coefficient function (which is a function). By using the
following code, you can access to: * **Bliss estimate**, a
piecewise constant version of the coefficient function, and *
**the smooth estimate**, the standard bayesian estimate of
the coefficient function (standard means that it minimizes the posterior
\(L^2\)-loss).

```
image_Bliss(res_bliss$beta_posterior_density,param,q=1) +
lines_bliss(res_bliss$data$grids[[1]],res_bliss$Bliss_estimate[[1]]) +
lines_bliss(res_bliss$data$grids[[1]],res_bliss$smooth_estimate[[1]],lty = "dashed")+
lines_bliss(res_bliss$data$grids[[1]],data$betas[[1]],col="purple")
```