[R] Help with fmodel in statisticalModeling package

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Fri Sep 6 15:04:06 CEST 2019


I have no clue about the internals of fmodel() (and no real intention of getting one...), but pragmatically and to avoid getting sidetracked, how about converting the bogus variable to zero-one:

CPS85$bogus <- as.numeric(rnorm(nrow(CPS85)) > 0)

-pd

> On 6 Sep 2019, at 11:57 , Paul Johnston <paul.johnston using manchester.ac.uk> wrote:
> 
> Hi
> 
> Anyone able to help me with this.
> I'm doing a datacamp course and the effect of adding a "bogus variable" to a linear model.
> I make a model and initially fmodel works fine.
> When I have a second model which uses this "bogus variable" it complains about the type of this variable.
> 
> The code below works fine.
> 
> library(statisticalModeling)
> library(mosaicData)
> print(names(CPS85))
> 
> # Add bogus column to CPS85 (don't change)
> CPS85$bogus <- rnorm(nrow(CPS85)) > 0
> cat ("typeof(CPS88$bogus) is:", typeof(CPS85$bogus), "\n")
> # Make the base model
> base_model <- lm(wage ~ educ + sector + sex, data = CPS85)
> print(fmodel(base_model))
> 
> # Make the bogus augmented model
> aug_model <- lm(wage ~ educ + sector +sex  + bogus, data = CPS85)
> #print(fmodel((aug_model)))
> 
> # Find the MSE of the base model
> mean_base <- mean((CPS85$wage - predict(base_model, newdata = CPS85)) ^ 2)
> 
> # Find the MSE of the augmented model
> mean_aug <- mean((CPS85$wage - predict(aug_model, newdata = CPS85)) ^ 2)
> cat("Mean Square Error of base", mean_base,"\n")
> cat("Mean Square Error of aug", mean_aug)
> 
> However if I uncomment #print(fmodel((aug_model)))
> I get
> 
> Error: variable 'bogus' was fitted with type "logical" but type "character" was supplied
> 
> Any pointers gratefully accepted
> 
> Cheer Paul J
> 
> 
> Paul Johnston
> Field Support (Slough House)
> University of Manchester
> Room B29
> Pariser  Building
> Tel 07826 875504
> IOSH Managing Safely
> Cert No.: 506572
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list