Learn R Programming

cossonet

Installation

We first load the library for cossonet and set a seed for reproducibility.

devtools::install_github("jiieunshin/cossonet")
library(cossonet)
set.seed(20250101)

Data generation

The function data_generation generates example datasets with continuous response. We generate a training set with $n=200$ and $p=20$, and a test set with $n=1000$ and $p=20$.

tr = data_generation(n = 200, p = 20, SNR = 9, response = "continuous")
te = data_generation(n = 1000, p = 20, SNR = 9, response = "continuous")

Model fitting

The function cossonet is the main function that fits the model. We have to input training set in this function. And Specific values are required to the arguments, such as family, lambda0, and lambda_theta`.

lambda0_seq = exp(seq(log(2^{-5}), log(2^{-1}), length.out = 20))
lambda_theta_seq = exp(seq(log(2^{-8}), log(2^{-5}), length.out = 20))

fit = cossonet(tr$x, tr$y, family = 'gaussian',
	       lambda0 = lambda0_seq,
	       lambda_theta = lambda_theta_seq
	       )

Prediction

The function cossonet.predict is used to predict new data based on the fitted model. The output includes predicted values $\hat{f}$ (from f.new) and $\hat{\mu}$ (from mu.new) for the new data. The predicted value and predictive accuracy for the test set using our fitted model can be obtained by

pred = cossonet.predict(fit, te$x)
mean((te$f - pred$f.new)^2)

Copy Link

Version

Install

install.packages('cossonet')

Monthly Downloads

134

Version

1.0

License

GPL-3

Maintainer

Jieun Shin

Last Published

March 13th, 2025

Functions in cossonet (1.0)

cossonet

Load a matrix from a file
metric

The function metric provides a contingency table for the predicted class and the true class for binary classes.
data_generation

The function data_generation generates an example dataset for applying the cossonet function.
cossonet.predict

The function cossonet.predict predicts predictive values for new data based on an object from the cossonet function.