Giter Site home page Giter Site logo

Comments (4)

jacob-long avatar jacob-long commented on June 11, 2024 1

Well @mattansb I think you've been proven right as I've gotten at least two emails about this same problem since you created this issue.

As it turns out, fixing this isn't as complicated as I first expected. The source of the problem was in my other package, jtools, and will be fixed with its next release (coming imminently).

To some extent, this is all just a quirk of how R automatically treats a one-dimensional matrix of numbers and a vector of numbers as if they are the same sometimes but not other times. Now my internal functions just do a check to see if what looks like a numeric variable is actually a one-dimensional matrix created by scale().

from interactions.

jacob-long avatar jacob-long commented on June 11, 2024

So it seems the source of this problem is that scale() returns a matrix, which is not recognized by these plotting functions since R otherwise lets me treat these one-dimensional matrices as if they are numeric vectors. But when I try to use the predict() function, R complains because it wants me to give it a matrix.

This is such an odd case that I'm not sure if it's worth me trying to anticipate and fix at this juncture.

A quick fix is to just do some simple coercion like this:

library(interactions)

iris$Sepal.Length_c <- as.numeric(scale(iris$Sepal.Length, center = TRUE, scale = FALSE))
iris$Sepal.Width_c <- as.numeric(scale(iris$Sepal.Width, center = TRUE, scale = FALSE))

fit <- lm(Petal.Length ~ Sepal.Length_c * Sepal.Width_c, iris)

interact_plot(fit, pred = Sepal.Length_c, modx = Sepal.Width_c)

from interactions.

mattansb avatar mattansb commented on June 11, 2024

This is such an odd case that I'm not sure if it's worth me trying to anticipate and fix at this juncture.

I'm afraid that odd as it is, it is also common to center variables, especially in moderation analyses (especially in the social sciences). One of those things that just "caught on" and cannot be untaught :/

from interactions.

mattansb avatar mattansb commented on June 11, 2024

Thanks Jacob!

from interactions.

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.