-
Notifications
You must be signed in to change notification settings - Fork 0
/
coef-sd.R
39 lines (35 loc) · 1.04 KB
/
coef-sd.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## ==================================================
## R Function by Chanseok Park
## (MTHSC 805-Clemson University, IE-68722-PNU)
##
## coef.sd (extracts standardized model coefficients.
##
## Usage: LM = lm ( y ~ x1 + x2 + x3 )
## coef.sd(LM) # standardized betas
##
## Note: coef(LM) # ordinary betas
## ==================================================
coef.sd <- function(object,...) UseMethod("coef.sd")
coef.sd.default <- function(object,...) stop("No default method for vif. Sorry.")
## standardized Betas
coef.sd.lm.old <-
function (object) {
# b = coef(object)[-1]
b = object$coefficients[-1]
sx = sd(object$model[-1])
sy = sd(object$model[1])
b.star = b * sx / sy
return(b.star)
}
## standardized Betas
coef.sd.lm <-
function (object) {
# b = coef(object)[-1]
b = object$coefficients[-1]
## sx = sd( as.matrix(object$model[-1]) )
tmp = as.matrix(object$model[-1])
sx = apply(tmp, 2, sd)
sy = sd( as.matrix(object$model[1]) )
b.star = b * sx / sy
return(b.star)
}