ProjectMOSAIC / mosaicModel

Utilities for creating, visualizing, and predicting with models
Other
2 stars 1 forks source link

allow user-specified confidence levels in mod_eval() and mod_output() #17

Closed rpruim closed 6 years ago

rpruim commented 6 years ago

done.

library(mosaicModel)
#> Loading required package: mosaicCore
#> Loading required package: splines
#> Loading required package: magrittr
mod1 <- lm(wage ~ age * sex + sector, data = mosaicData::CPS85)
mod_eval(mod1, interval = "prediction") # 95% confidence level
#>   age sex   sector model_output      lower    upper
#> 1   0   M     prof     8.914945 -0.1165512 17.94644
#> 2 100   M     prof    20.019749 10.6733678 29.36613
#> 3   0   F     prof     9.172299  0.1237554 18.22084
#> 4 100   F     prof    13.727640  4.3772696 23.07801
#> 5   0   M clerical     5.096372 -3.9437249 14.13647
#> 6 100   M clerical    16.201176  6.8203084 25.58204
#> 7   0   F clerical     5.353726 -3.6909856 14.39844
#> 8 100   F clerical     9.909067  0.5653999 19.25273
mod_eval(mod1, interval = "prediction", level = 0.9)
#>   age sex   sector model_output     lower    upper
#> 1   0   M     prof     8.914945  1.339596 16.49029
#> 2 100   M     prof    20.019749 12.180284 27.85921
#> 3   0   F     prof     9.172299  1.582652 16.76195
#> 4 100   F     prof    13.727640  5.884829 21.57045
#> 5   0   M clerical     5.096372 -2.486191 12.67893
#> 6 100   M clerical    16.201176  8.332785 24.06957
#> 7   0   F clerical     5.353726 -2.232707 12.94016
#> 8 100   F clerical     9.909067  2.071879 17.74626
mod2 <- 
  glm(married == "Married" ~ age + sex * sector, 
      data = mosaicData::CPS85, family = "binomial")
mod_eval(mod2, nlevels = 2, sex = "F")
#> Warning in predict.lm(object, newdata, se.fit, scale = 1, type =
#> ifelse(type == : prediction from a rank-deficient fit may be misleading
#>   age sex   sector model_output
#> 1   0   F     prof    0.1608223
#> 2 100   F     prof    0.9847174
#> 3   0   F clerical    0.1896298
#> 4 100   F clerical    0.9874492
mod_eval(mod2, nlevels = 2, sex = "F", interval = "confidence", level = 0.9)
#> Warning in predict.lm(object, newdata, se.fit, scale = residual.scale, type
#> = ifelse(type == : prediction from a rank-deficient fit may be misleading
#>   age sex   sector model_output      lower     upper
#> 1   0   F     prof    0.1608223 0.08390278 0.2862267
#> 2 100   F     prof    0.9847174 0.95472247 0.9949468
#> 3   0   F clerical    0.1896298 0.10552564 0.3170088
#> 4 100   F clerical    0.9874492 0.96322332 0.9957866

Created on 2018-06-21 by the reprex package (v0.2.0).

nicholasjhorton commented 6 years ago

Is there any way to elide the:

"ifelse(type == : prediction from a rank-deficient fit may be misleading"

message in there? I think that I know what it is there (but it's offputting).