Function to standardize the columns of a matrix, used to standardize the model matrix before estimating the regression coefficients of a generalized linear model (iwls_logit).

Destandardize coefficients. Brings coefficients back to the "real" scale if standardized coefficients are used when estimating the logistic regression model (concomitant model).

standardize(x, ...)

# S3 method for matrix
standardize(x, ...)

# S3 method for standardized
scale(x, ...)

# S3 method for standardized
destandardize(x, ...)

destandardize_coefficients(beta, X)

Arguments

x

matrix of dimension N x p.

...

additional arguments, ignored.

beta

regression coefficients estimated on standardized data.

X

object of class standardize.

Value

Returns a matrix of the same dimension as input x

but with standardized data. The return object is of class c("standardized", "matrix") which comes with some handy S3 methods.

Returns 'scaled:scale' used for standardization

Returns destandardized regression coefficients, same object as input beta.

See also

standardize. Used in foehnix and iwls_logit.

Author

Reto Stauffer

Examples

# Example data set
data("airquality")
airquality <- na.omit(airquality)

# Create model matrix
X <- model.matrix(Ozone ~ ., data = airquality)
print(head(X))
#>   (Intercept) Solar.R Wind Temp Month Day
#> 1           1     190  7.4   67     5   1
#> 2           1     118  8.0   72     5   2
#> 3           1     149 12.6   74     5   3
#> 4           1     313 11.5   62     5   4
#> 7           1     299  8.6   65     5   7
#> 8           1      99 13.8   59     5   8

# Standardize
S <- standardize(X)
print(head(S))
#>   (Intercept)     Solar.R       Wind       Temp     Month        Day
#> 1           1  0.05702761 -0.7138405 -1.1325108 -1.504117 -1.7165054
#> 2           1 -0.73285918 -0.5451928 -0.6078501 -1.504117 -1.6016578
#> 3           1 -0.39276904  0.7477726 -0.3979858 -1.504117 -1.4868103
#> 4           1  1.40641756  0.4385852 -1.6571715 -1.504117 -1.3719627
#> 7           1  1.25282846 -0.3765451 -1.3423751 -1.504117 -1.0274200
#> 8           1 -0.94130153  1.0850679 -1.9719679 -1.504117 -0.9125725

is.standardized(X)
#> [1] FALSE
is.standardized(S)
#> [1] TRUE

# Get parameters used for standardization
center(S)
#> (Intercept)     Solar.R        Wind        Temp       Month         Day 
#>    0.000000  184.801802    9.939640   77.792793    7.216216   15.945946 
scale(S)
#> (Intercept)     Solar.R        Wind        Temp       Month         Day 
#>    1.000000   91.152302    3.557713    9.529969    1.473434    8.707194 

# Destandardize
D <- destandardize(S)

# Check
all.equal(D, X, check.attributes = FALSE)
#> [1] TRUE