[R] Help with fmodel in statisticalModeling package
p@u|@john@ton @end|ng |rom m@nche@ter@@c@uk
Fri Sep 6 15:11:01 CEST 2019
Many thanks, as you suggest that does allow the program to run.
As does (no pun intended) as.character()
If anyone knows what causes this I would be still keen to know.
From: peter dalgaard [mailto:pdalgd using gmail.com]
Sent: 06 September 2019 14:04
To: Paul Johnston <paul.johnston using manchester.ac.uk>
Cc: R-help using r-project.org
Subject: Re: [R] Help with fmodel in statisticalModeling package
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)
> On 6 Sep 2019, at 11:57 , Paul Johnston <paul.johnston using manchester.ac.uk> wrote:
> 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.
> # 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)
> # Make the bogus augmented model
> aug_model <- lm(wage ~ educ + sector +sex + bogus, data = CPS85)
> # 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
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-help