Learn R Programming

fifer (version 1.1)

scaleB: Standardize coefficients

Description

Generic function for obtaining scaled coefficients

Usage

scaleB(object, scale.response = F)

Arguments

object
an object resulting from glm, lm, or lda
scale.response
should the response variable be scaled as well? (Usually not for glm or lda).

Value

an object of the same class as the one outputted

Details

Given an object of class lm, glm, or lda, this function will first standardize the variables, then run the model again. The resulting coefficients will be standardized betas.

Examples

Run this code
		#### create random data with different means and variances
d = data.frame(matrix(rnorm(5*50, c(10,5,14,100, 33), c(3,5,4,3,5)), nrow=50, byrow=TRUE))
names(d) = LETTERS[1:5]
g = lm(C~B + A + D + E, data=d)
scaleB(g, TRUE)
##### make a logistic
d$A = as.factor(as.numeric(cut(d$A, 2, labels=c(1,0))	))
object = glm(A~B + C + D + E, data=d, family=binomial)
scaleB(object)
##### LDA
object = lda(A~B + C + D + E, data=d, family=binomial)
scaleB(object)

Run the code above in your browser using DataLab