-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
475 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tempName": "Untitled1", | ||
"cursorPosition": "3,7", | ||
"scrollLine": "0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tempName": "Untitled1", | ||
"cursorPosition": "75,17", | ||
"scrollLine": "48", | ||
"last_setup_crc32": "9F8C73CAbb338d19" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"tempName": "Untitled1", | ||
"cursorPosition": "23,27", | ||
"scrollLine": "1" | ||
"cursorPosition": "23,8", | ||
"scrollLine": "0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"id": "254CACE3", | ||
"path": "H:/UbuntuRv2/IBGS/IBGS/R/blockgibbs.R", | ||
"project_path": "R/blockgibbs.R", | ||
"type": "r_source", | ||
"hash": "0", | ||
"contents": "", | ||
"dirty": false, | ||
"created": 1637272959110.0, | ||
"source_on_save": false, | ||
"relative_order": 6, | ||
"properties": { | ||
"tempName": "Untitled2", | ||
"cursorPosition": "46,37", | ||
"scrollLine": "25" | ||
}, | ||
"folds": "", | ||
"lastKnownWriteTime": 1637239897, | ||
"encoding": "UTF-8", | ||
"collab_server": "", | ||
"source_window": "", | ||
"last_content_update": 1637239897, | ||
"read_only": false, | ||
"read_only_alternatives": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' The iterated block Gibbs sampler algorithm | ||
#' | ||
#' @param y the response variable | ||
#' @param x the predictors | ||
#' @param H the number of predictors in small groups, default is 30 | ||
#' @param kapp the number of selected predictors in first step, default is 20 | ||
#' @param tau the threshold to select the important predictors in second step, default is 0.9 | ||
#' @param len the half number of generated samples, default is 200 | ||
#' @param k the tuning parameter, default is 1 | ||
#' @param gamma the parameter for extended BIC, default is 0.5 | ||
#' @param info the selected model selection criterion from AIC, AICc, BIC and exBIC | ||
#' @param family the type of model from linear, logistic, poisson | ||
#' @param n.iter the number of iterations | ||
#' @param n.models the number of top selected models | ||
#' | ||
#' @return a list contains a summary of final result | ||
#' @export | ||
|
||
BlockGibbsSampler <- function(y, x, n.iter = 3, n.models =10, H = 30, kapp = 20, | ||
tau = 0.9, len = 200, k = 1, gamma = 0.5, | ||
info = c("AIC", "BIC", "AICc", "exBIC"), | ||
family = c("gaussian","poisson", "binomial")){ | ||
p <- dim(x)[2] | ||
x.predictors <- colnames(x) | ||
colnames(x) <- 1:p | ||
|
||
x1 <- x | ||
x2 <- vector() | ||
|
||
if(n.iter < 2){ | ||
result <- BlockGibbsSampler.step3(y, x1, x2, n.models, x.predictors, H, | ||
kapp, tau, len, k, gamma, p, info, family) | ||
} | ||
else{ | ||
j <- 1 | ||
while(j < n.iter){ | ||
v.select <- BlockGibbsSampler.step2(y, x1, x2, H, kapp, tau, len, k, | ||
gamma, p, info, family) | ||
x1 <- x[, -v.select] | ||
x2 <- x[, v.select] | ||
|
||
j <- j+1 | ||
} | ||
result <- BlockGibbsSampler.step3(y, x1, x2, n.models, x.predictors, H, | ||
kapp, tau, len, k, gamma, p, info, family) | ||
} | ||
result$x.predictors <- x.predictors | ||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"id": "462FD7FF", | ||
"path": "H:/UbuntuRv2/TCGS/IBGS.Rmd", | ||
"project_path": null, | ||
"type": "r_markdown", | ||
"hash": "2363041877", | ||
"contents": "", | ||
"dirty": false, | ||
"created": 1637269087029.0, | ||
"source_on_save": false, | ||
"relative_order": 5, | ||
"properties": { | ||
"tempName": "Untitled1", | ||
"cursorPosition": "75,17", | ||
"scrollLine": "48", | ||
"last_setup_crc32": "9F8C73CAbb338d19" | ||
}, | ||
"folds": "", | ||
"lastKnownWriteTime": 1637272918, | ||
"encoding": "UTF-8", | ||
"collab_server": "", | ||
"source_window": "", | ||
"last_content_update": 1637272918280, | ||
"read_only": false, | ||
"read_only_alternatives": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: "An introduction to IBGS" | ||
author: "Lizhong Chen" | ||
date: "11/19/2021" | ||
output: | ||
pdf_document: default | ||
html_document: | ||
df_print: paged | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
## Introduction | ||
|
||
Here is a brief introduction to the R package "IBGS". The iterated block Gibbs sampler is a powerful variable selection method in high dimensions. It is important to identify the potential predictors which has significant influence on the response variable. | ||
|
||
The "IBGS" package works for the generalized linear models including linear, logistic and poisson models and uses AIC, AICc, BIC, and exBIC as the model selection criterion. | ||
|
||
There are two main goals for "IBGS" package: | ||
|
||
* Identify the important predictors with the marginal probability | ||
|
||
* Make a prediction based on the best selected model or model averaging using top selected models | ||
|
||
## Install | ||
|
||
To install and load the "IBGS" package, use this command | ||
```{r, echo=FALSE} | ||
cat("install.packages(\"IBGS_0.1.0.tar.gz\", repos = NULL)\nlibrary(IBGS)") | ||
``` | ||
|
||
The "IBGS" package requires "doParallel" package. Please ensure that "doParallel" package is installed and loaded, then set up the register-cores. | ||
```{r, echo=FALSE} | ||
cat("library(doParallel)\nregisterDoParallel(ncores)\n") | ||
``` | ||
where ncores is the number of CPU cores used in the calculation. | ||
|
||
## Main function | ||
|
||
The main function is | ||
```{r, echo=FALSE} | ||
cat("BlockGibbsSampler <- function(y, x, n.iter = 3, n.models =10, H = 30, kapp = 20, | ||
tau = 0.9, len = 200, k = 1, gamma = 0.5, | ||
info = c(\"AIC\", \"BIC\", \"AICc\", \"exBIC\"), | ||
family = c(\"gaussian\",\"poisson\", \"binomial\"))") | ||
``` | ||
For details, please use help document. | ||
```{r, echo=FALSE} | ||
cat("?BlockGibbsSampler") | ||
``` | ||
|
||
## Example | ||
|
||
Here is an example to show how "IBGS" works. We use the tropical cyclone genesis data. | ||
```{r, echo=FALSE} | ||
load("tcg_ar.RData") | ||
``` | ||
|
||
It has 1856 samples and 149 predictors. | ||
```{r, collapse=TRUE} | ||
dim(x) | ||
``` | ||
We divide the data into train and test set and use the train set ($\approx 80\%$ of data) to run "IBGS" algorithm. Then we use the test set ($\approx 20\%$ of data) to verify the results. | ||
|
||
The simple following command is used | ||
```{r} | ||
cat("model <- BlockGibbsSampler(y_train, x_train, info = \"exBIC\", family = \"binomial\")") | ||
``` | ||
We only need to specify the response, predictors, the model selection criterion and the model type. | ||
### Variable ranking | ||
|
||
We can plot the marginal probabilities for those important predictors using plots.Gibbs command. | ||
```{r, collapse=TRUE} | ||
plots.Gibbs(model) | ||
``` | ||
|
Oops, something went wrong.