Giter Site home page Giter Site logo

Comments (5)

bixiou avatar bixiou commented on June 23, 2024

PS: I corrected a typo in my post. With the typo there was no error. Now, there is the error.

from memisc.

melff avatar melff commented on June 23, 2024

This is not a bug, but a feature. Values equal to 0 are translated into NA by as.character() because 0 is marked as a missing value. Such an automatic translation into NA is the whole point of the "item" class, because otherwise there is no way in R to distinguish between "non-NA" missing values and NA.

If you want to retain "PNR" as a valid factor level, you have to declare 0 as valid.
E.g. by

missing.values(foo) <- NULL
bar <- as.factor(foo)
bar <- relevel(bar, 'PNR')

or

valid.values(foo) <- -1:1
bar <- as.factor(foo)
bar <- relevel(bar, 'PNR')

or

bar <- as.factor(include.missings(foo))
bar <- relevel(bar, 'PNR')

If in earlier versions of memisc as.character() did not take into account the missingness status of certain values then that was a bug.

from memisc.

bixiou avatar bixiou commented on June 23, 2024

Well, this is a pity because this "bug" was really convenient: it allowed me to run regressions without dropping data ('PNR' were considered as a response category, which it is) while allowing me to treat these 'PNR' as missing in the analysis (i.e. have
a special status for descriptive stats, graphs...).
So I'll keep using memisc 0.99.22 which does exactly what I need.

from memisc.

melff avatar melff commented on June 23, 2024

I think

bar <- as.factor(as.character(include.missings(foo)))

or

bar <- as.factor(as.character(foo,include.missings=TRUE))

will do what you want it to do with newer versions of memisc.

from memisc.

bixiou avatar bixiou commented on June 23, 2024

In this particular case, yes, because I convert the variable in a factor anyway. But I noticed other parts of the code where the update causes issues, namely regressions. I'd need to transform each item variable to a factor in my regressions with the new memisc version. Easier (and more compact code) to keep the old one.

from memisc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.