plsmmLasso

Variable Selection and Inference for Partial Linear Mixed-Effects Model

https://github.com/sami-leon/plsmmlasso

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.7%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Variable Selection and Inference for Partial Linear Mixed-Effects Model

Basic Info
  • Host: GitHub
  • Owner: Sami-Leon
  • License: gpl-3.0
  • Language: R
  • Default Branch: main
  • Size: 1.37 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Created over 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# plsmmLasso



[![R-CMD-check](https://github.com/Sami-Leon/plsmmLasso/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Sami-Leon/plsmmLasso/actions/workflows/R-CMD-check.yaml)



The objective of plsmmLasso is to facilitate the estimation of a Regularized Partial Linear Semiparametric Mixed-Effects Model (PLSMM) through a dictionary approach for modeling the nonparametric component. The model employs a set of bases functions and automatically selects them using a lasso penalty. Additionally, it conducts variable selection on the fixed-effects using another lasso penalty. The implementation also supports the inclusion of a random intercept.

## Installation

You can install the development version of plsmmLasso from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("Sami-Leon/plsmmLasso")
```

## Example I: A Guide to Fitting, Visualization, and Inference

### Fitting the model

Here's a basic example using a simulated dataset to demonstrate how to utilize the main functions of the plsmmLasso package. This example assumes an effect of a grouping variable and different nonlinear functions for each group.

```{r example}
library(plsmmLasso)

# Simulate a dataset
set.seed(123)
data_sim <- simulate_group_inter(
  N = 50, n_mvnorm = 3, grouped = TRUE,
  timepoints = 3:5, nonpara_inter = TRUE,
  sample_from = seq(0, 52, 13), 
  cos = FALSE, A_vec = c(1, 1.5)
)
sim <- data_sim$sim

# Fit the data
x <- as.matrix(sim[, -1:-3])
y <- sim$y
series <- sim$series
t <- sim$t
bases <- create_bases(t)
lambda <- 0.0046
gamma <- 0.00001
plsmm_output <- plsmm_lasso(x, y, series, t,
  name_group_var = "group", bases$bases,
  gamma = gamma, lambda = lambda, timexgroup = TRUE,
  criterion = "BIC"
)
```

One of the most important output of the `plsmm_lasso()` function is the estimates of the fixed-effects.

```{r}
plsmm_output$lasso_output$theta
```

Here, we observe that some covariates have small values, but most are non-zero. If we desire more regularization for the fixed-effects, we can use a larger value for lambda.

### Hyperparameter tuning

```{r}
lambda <- 0.1
plsmm_output <- plsmm_lasso(x, y, series, t,
  name_group_var = "group", bases$bases,
  gamma = gamma, lambda = lambda, timexgroup = TRUE,
  criterion = "BIC"
)
plsmm_output$lasso_output$theta
```

With a larger lasso penalty, more coefficients are set to zero. 

The coefficients associated with the nonlinear functions are denoted by alpha.

```{r}
head(plsmm_output$lasso_output$alpha)
```

Similar behavior would be observed for the alpha values if we were to increase the value of gamma.

To find optimal values for gamma and lambda, we tune these hyperparameters using BIC-type criteria with the `tune_plsmm()` function and a grid search.

```{r}
lambdas <- gammas <- round(exp(seq(log(1), log(1 * 0.00001),
              length.out = 5
)), digits = 5)

tuned_plsmm <- tune_plsmm(x, y, series, t,
                       name_group_var = "group", bases$bases,
                       gamma_vec = gammas, lambda_vec = lambdas, timexgroup = TRUE,
                       criterion = "BIC"
)
```

The `tune_plsmm()` function tries every possible combination of the values from lambdas and gammas and returns the model with the best BIC (other options are BICC and EBIC). This example is for illustration purposes only; in practice, a more exhaustive grid should be used.

### Plotting the results

The `plot_fit()` function allows for the visualization of the estimated mean trajectories as well as the estimate of the nonlinear functions. By default, only the observed time points are being used. To use continuous time points, the argument `predicted` can be set to `TRUE`.

```{r}
plot_fit(x, y, series, t, name_group_var = "group", tuned_plsmm)

plot_fit(x, y, series, t, name_group_var = "group", tuned_plsmm, predicted = TRUE)
```

### Post-selection inference

To compute p-values on the fixed-effects, the `debias_plsmm()` function can be used.

```{r}
debias_plsmm(x, y, series, tuned_plsmm)
```

The function reports the original coefficients, debiased coefficients, standard errors, confidence intervals and p-values. These p-values are already adjusted for the selection process of the lasso, and provide valid inference.

### Test on the nonlinear functions

Finally, we can perform tests on the nonlinear functions. The first element of the list is an overall test of equality. If the p-value is $< 0.05$, we reject the null hypothesis of equality and conclude that overall the two nonlinear functions are different. To obtain a comparison at each time point, confidence bands are computed, and a figure displaying these confidence bands is generated. For the time points associated with confidence bands that include $0$, we cannot reject the null hypothesis that the nonlinear functions are the same for this time point. The data frame that is used to generate this figure can be found in the second element of the output list.

```{r}
test_f_results <- test_f(x, y, series, t,
 name_group_var = "group", tuned_plsmm,
 n_boot = 10, verbose = TRUE
)
test_f_results[[1]]
head(test_f_results[[2]])
```

Similarly to the `plot_fit()` function, the argument `predicted` can be changed to `TRUE` to display the joint confidence bands as a continuous function of time rather than at the observed time points only.

```{r}
test_f_results <- test_f(x, y, series, t,
 name_group_var = "group", tuned_plsmm,
 n_boot = 10, predicted = TRUE
)
```

## Example II: Flexibility of the Model

### Model fitting without group-specific nonlinear functions

The plsmmLasso package offers flexibility; if the nonlinear functions do not differ between groups, the `timexgroup` argument can be set to `FALSE`. Below, we simulate a dataset where the nonlinear functions are the same and fit the data accordingly.

```{r}
# Simulate a dataset with equal nonlinear functions per group
set.seed(123)
data_sim <- simulate_group_inter(
  N = 50, n_mvnorm = 3, grouped = TRUE,
  timepoints = 3:5, nonpara_inter = FALSE,
  sample_from = seq(0, 52, 13), 
  cos = FALSE, A_vec = c(1, 1.5)
)
sim <- data_sim$sim

# Fit the data
x <- as.matrix(sim[, -1:-3])
y <- sim$y
series <- sim$series
t <- sim$t
bases <- create_bases(t)
tuned_plsmm <- tune_plsmm(x, y, series, t,
                       name_group_var = "group", bases$bases,
                       gamma_vec = gammas, lambda_vec = lambdas, timexgroup = FALSE,
                       criterion = "BIC"
)

plot_fit(x, y, series, t, name_group_var = "group", tuned_plsmm)
```

As observed, the estimates of the nonlinear functions are identical. 


### Model fitting without grouping variable

It is also possible not to use any grouping variable for the `name_group_var` argument. Here, we simulate a dataset without the effect of a grouping variable, resulting in no difference in the height of the overall mean trajectories and using the same nonlinear functions.

```{r}
# Simulate a dataset with no group effect
set.seed(123)
data_sim <- simulate_group_inter(
  N = 50, n_mvnorm = 3, grouped = FALSE,
  timepoints = 3:5, nonpara_inter = FALSE,
  sample_from = seq(0, 52, 13), 
  cos = FALSE, A_vec = c(1, 1.5)
)
sim <- data_sim$sim

# Fit the data
x <- as.matrix(sim[, -1:-3])
y <- sim$y
series <- sim$series
t <- sim$t
bases <- create_bases(t)
tuned_plsmm <- tune_plsmm(x, y, series, t,
                       name_group_var = NULL, bases$bases,
                       gamma_vec = gammas, lambda_vec = lambdas, timexgroup = FALSE,
                       criterion = "BIC"
)

plot_fit(x, y, series, t, name_group_var = NULL, tuned_plsmm)
```

Only one figure is displayed now since there is no grouping variable.

Owner

  • Login: Sami-Leon
  • Kind: user
  • Location: Rochester, NY
  • Company: University of Rochester

GitHub Events

Total
Last Year

Packages

  • Total packages: 1
  • Total downloads:
    • cran 204 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: plsmmLasso

Variable Selection and Inference for Partial Semiparametric Linear Mixed-Effects Model

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 204 Last month
Rankings
Dependent packages count: 28.0%
Dependent repos count: 36.0%
Average: 49.7%
Downloads: 85.1%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • MASS * imports
  • dplyr * imports
  • ggplot2 * imports
  • glmnet * imports
  • hdi * imports
  • mvtnorm * imports
  • rlang * imports
  • scalreg * imports
  • stats * imports