Skip to content

Commit

Permalink
Handle missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemken authored and Hemken committed Aug 3, 2017
1 parent 251bdba commit aad2cdc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: stdBeta
Type: Package
Title: Standardized Coefficients for Linear Models
Description: Updates a model fit by substituting standarized variables.
Version: 0.2.2
Version: 0.2.3
Authors@R: person("Doug", "Hemken", email="[email protected]",
role=c("aut", "cre"), comment="SSCC, Univ. of Wisconsin-Madison")
Maintainer: Doug Hemken <[email protected]>
Expand Down
3 changes: 2 additions & 1 deletion R/stdBeta.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ stdBeta <- function(lmfit) {
# print(sapply(stddata, data.class))
stopifnot(all(sapply(stddata, data.class) %in% c("numeric", "factor", "AsIs")))
numvars <- sapply(stddata[, modelvars], is.numeric)
stddata[, modelvars][, numvars] <- sapply(stddata[, modelvars][, numvars], scale)
stddata <- stats::na.omit(stddata[, modelvars])
stddata[, numvars] <- sapply(stddata[, numvars], scale)
# head(df)
stats::update(lmfit, data=stddata)
}
3 changes: 2 additions & 1 deletion inst/doc/polnomials.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ mtcars[, modelvars] <- sapply(mtcars[, modelvars], scale)
summary(update(fit4, data=mtcars))
rm(mtcars)

stdBeta::stdBeta(fit4) # blocked
QuantPsyc::lm.beta(fit4) # Wrong, with WARNING
lm.beta::lm.beta(fit4) # wrong, no warning
lsr::standardCoefs(fit4) # again wrong, no warning
arm::standardize(fit4, standardize.y=TRUE) # wrong, but no error
stdBeta::stdBeta(fit4) # good

13 changes: 9 additions & 4 deletions vignettes/Why_stdBeta.rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "stdBeta"
author: "Doug Hemken"
date: "July 2017"
date: "August 2017"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Why stdBeta?}
Expand All @@ -11,9 +11,14 @@ vignette: >

## Do we really need another function that standardizes coefficients?
There are several R functions out there that will return \'standardized
coefficients\' of one sort or another. My chief complaint with them
all is that they are difficult to interpret when the model includes
interaction terms (or polynomial terms, for that matter).
coefficients\' of one sort or another. Three of these work fine for
models with no interaction or polynomial terms, but fail to produce
the expected results where these higher order terms are present.
Two of these produce valid models, in the sense that they produce
the correct predicted values and residuals. However, they are
difficult to interpret when the model includes
higher order terms, because similar-looking variables are not
on the same scales.

Other package::functions that return standardized coefficients:

Expand Down

0 comments on commit aad2cdc

Please sign in to comment.