Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

std

Standardizes a design matrix


Description

The function std accepts a design matrix and returns a standardized version of that matrix (i.e., each column will have mean 0 and mean sum of squares equal to 1).

Usage

std(X)

Arguments

X

A matrix (or object that can be coerced to a matrix, such as a data frame or numeric vector).

Details

This function centers and scales each column of X so that

sum(X[,j])=0

and

mean(X[,j]^2)=1

for all j. This is usually not necessary to call directly, as ncvreg internally standardizes the design matrix, but inspection of the standardized design matrix can sometimes be useful. This differs from the base R function scale in two ways:

  1. scale uses the sample standard deviation sqrt(sum(x^2)/(n-1)), while std uses the root-mean-square (population) standard deviation sqrt(mean(sum(x^2)))

  2. std is faster.

Value

The standardized design matrix, with the following attribues:

  • center, scale: mean and standard deviation used to scale the columns

  • nonsingular: A vector indicating which columns of the original design matrix were able to be standardized (constant columns cannot be standardized to have a standard deviation of 1)

Examples

X <- matrix(rnorm(50), 10, 5)
S <- std(X)
apply(S, 2, sum)
apply(S, 2, function(x) mean(x^2))

ncvreg

Regularization Paths for SCAD and MCP Penalized Regression Models

v3.13.0
GPL-3
Authors
Patrick Breheny [aut, cre] (<https://orcid.org/0000-0002-0650-1119>)
Initial release
2021-03-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.