Giter Site home page Giter Site logo

jacob-long / interactions Goto Github PK

View Code? Open in Web Editor NEW
127.0 127.0 17.0 38.68 MB

A comprehensive, user-friendly toolkit for visualizing and analyzing statistical interactions. A spinoff from the `jtools` package.

Home Page: https://interactions.jacob-long.com

License: Other

R 99.78% CSS 0.22%
interactions moderation r r-package rstats social-sciences statistics

interactions's People

Contributors

jacob-long avatar ngreifer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

interactions's Issues

Error: `expr` must quote a symbol, scalar, or call

Hi there,

I'm having issues with running the interactions package with my data and models (lmer). I've tried it a bunch of ways, and it's not even working with simple code. I tried using the code on your website and it gives me the same error, for simplicity's sake, I'll post that code.

library(interactions)
fitiris <- lm(Petal.Length ~ Petal.Width * Species, data = iris)
interact_plot(fitiris, pred = Petal.Width, modx = Species, plot.points = TRUE)

This gets the following error
Error: expr must quote a symbol, scalar, or call

When I run tracebak() this is what the ouptput is:

6: stop(cnd)
5: abort("expr must quote a symbol, scalar, or call")
4: switch_type(expr, symbol = as_string(expr), quosure = , language = {
name <- deparse_one(expr)
name <- gsub("\n.$", "...", name)
name
}, if (is_scalar_atomic(expr)) {
as.character(expr)
} else if (length(expr) == 1) {
name <- expr_text(expr)
name <- gsub("\n.
$", "...", name)
name
} else {
abort("expr must quote a symbol, scalar, or call")
})
3: expr_name(quo_squash(quo))
2: quo_name(enexpr(mod2))
1: interact_plot(fitiris, pred = Petal.Width, modx = Species, plot.points = TRUE)

Any help you could provide would be fantastic. Thanks!

including survival models?

Hi! Excellent package, it opened new ways to interpret my data, so I am more than grateful! I just wanted to ask, would it be possible to include survival models (coxph and coxme) too? I have to deal with latency data a lot and it would be excellent to use interactions to explore covariate interactions in more detail.

R: modx.labels() in interactions::sim_slopes()

Hello,

I am working with sim_slopes() in the R package interactions. Running the code below, the requested labels "min", "mean", and "max" do not appear in the output. Am I doing something wrong?

Thanks in advance for any suggestions.

Dave

  dat=data.frame(state.x77)
  reg.mod = lm(data=dat, Murder ~ Illiteracy * HS.Grad)
  sim_slopes(reg.mod, pred = Illiteracy, modx = HS.Grad,
    modx.values = c(min(dat$HS.Grad), mean(dat$HS.Grad),
    max(dat$HS.Grad)), modx.labels = c('Min', 
    'Mean', 'Max'))


JOHNSON-NEYMAN INTERVAL 

When HS.Grad is INSIDE the interval [-17.49, 63.42], the slope of Illiteracy is p < 
.05.

Note: The range of observed values of HS.Grad is [37.80, 67.30]

SIMPLE SLOPES ANALYSIS 

Slope of Illiteracy when HS.Grad = 37.80: 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  5.65   1.43     3.95   0.00

Slope of Illiteracy when HS.Grad = 53.11: 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  3.87   0.84     4.61   0.00

Slope of Illiteracy when HS.Grad = 67.30: 

  Est.   S.E.   t val.      p
------ ------ -------- ------
  2.22   1.60     1.39   0.17

limit the range of the y-axis in the interaction plot

Kudos for your packages :-)
Is it possible to limit the range of the y-axis in the interaction plot using interact_plot? If not would it be possible to include that as an option? Or is there a workaround?

best
Maurice

error in sim_slopes/probe_interaction

Dear Jacob,

I am getting an error message using probe_interaction (with the newest interactions version 1.1.0).
The model was estimated with lme4:
mixed.RT = lmer(RT ~ contfactor1factor2 + factor1*factor3 + (cont|Code), REML = TRUE, data=mydata)

probe_interaction(mixed.RT, pred = cont, modx = factor1, mod2 = factor2, alpha = .05)

Error: One of the requested columns does not exist.
Backtrace:

  1. interactions::probe_interaction(...)
  2. interactions::sim_slopes(...)
  3. jtools:::summ.merMod(...)
  4. jtools:::create_table(...)

I do not encouter any problems with the same data/code using an old jtools version

Thank you for your time!

probe_interaction() does not work with centered = "none", digits = 3

sim_slopes(..., centered = "none", digits = 3, ...) can be used when centring of terms is unwanted and when 3 decimal places is wanted, but probe_interaction(), which calls on sim_slopes(), does not allow both centered = "none" and digits = 3 at the same time, with the following error: Error in digits + 1L : non-numeric argument to binary operator.

centered = "none" and digits = 3 can, however, be used separately.

Reproducible example:

set.seed(0)
data = data.frame(x = c(0,0,0,0,0,0,0,1,1,1,1), m = -5:5, c = rnorm(11))
data$y = 5 * data$x * data$m + rnorm(11)

res = lm(y ~ x*m + x*c, data = data)
summary(res)

# these can run
interactions::sim_slopes(res, pred = x, modx = m)
interactions::sim_slopes(res, pred = x, modx = m, centered = "none", digits = 3)

# these can run
interactions::probe_interaction(res, pred = x, modx = m)
interactions::probe_interaction(res, pred = x, modx = m, centered = "none")
interactions::probe_interaction(res, pred = x, modx = m, digits = 3)

# this wont run
interactions::probe_interaction(res, pred = x, modx = m, centered = "none", digits = 3)
# Error in digits + 1L : non-numeric argument to binary operator

Setting digits = 5, on the other hand, gives output with 324 decimal places

Code:
interactions::probe_interaction(res, pred = x, modx = m, centered = "none", digits = 5)

Output:

There were 16 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
2: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
3: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
4: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
5: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
6: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
7: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
8: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
9: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
10: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
11: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
12: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
13: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
14: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
15: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324
16: In formatC(x, digits = digits, format = format) : 'digits' reduced to 324

cat_plot discrepancy for mod2

When trying to specify mod2 vals in cat_plot, mod2vals="terciles" is common across your package. But in cat_plot, it's looking for modxvals2, not mod2vals . Small difference, easy to adjust on the user side, but I'm not sure if this was intended.

Aka from the vignette (it doesn't really make sense to do it here to be fair)

The line geom looks good for an ordered factor predictor

jtools::cat_plot(fit3, pred = cyl, modx = fwd, mod2 = auto, geom = "line",
interval = TRUE,
modxvals=NULL,
mod2vals="terciles")

Error in paste(modx, "=", modxvals2) : object 'modxvals2' not found

jtools::cat_plot(fit3, pred = cyl, modx = fwd, mod2 = auto, geom = "line",
interval = TRUE,
modxvals=NULL,
modxvals2="terciles")

prints

Different Johnson-Neyman intervals from johnson_neyman and sim_slopes when including quadratic terms

Thanks for this great package. I am getting inconsistent Johnson-Neyman intervals where I would expect the same output. I am not entirely sure if my analysis strategy is correct - I am including squared terms for the two variables that interact to ensure that the interaction is not just a spurious result due to the presence of a quadratic effect and a correlation between the two variables. If it is not, this problem might never arise with correct analyses - as it stands, however, I cannot explain the discrepancy between the two results shown below:

library(interactions)
mod <- lm(mpg ~ wt*cyl + I(wt^2) + I(cyl^2), mtcars)
johnson_neyman(mod, pred = "wt", modx = "cyl")
#> JOHNSON-NEYMAN INTERVAL 
#> 
#> When cyl is OUTSIDE the interval [-3.56, 1.29], the slope of wt is p < .05.
#> 
#> Note: The range of observed values of cyl is [4.00, 8.00]
sim_slopes(mod, pred = "wt", modx = "cyl")
#> JOHNSON-NEYMAN INTERVAL 
#> 
#> When cyl is INSIDE the interval [3.99, 6.61], the slope of wt is p < .05.
#> 
#> Note: The range of observed values of cyl is [4.00, 8.00]
#> 
#> SIMPLE SLOPES ANALYSIS 
#> (omitted)

Created on 2021-02-01 by the reprex package (v0.3.0)

The documentation of sim_slopes refers to johnson_neyman for information on that test - if it calculates the interval differently, and that difference is intended, a note to that effect might be needed there?

Unable to plot interaction of plm output

Hello. I'm trying to plot the interaction of a plm output, but it keeps giving me the following error. I've tried uninstalling and reinstalling R and the packages therein, but to no avail. Would you be so kind as to help figure out what is happening? Your help is much appreciated. Thank you!

Model run:
plm(data = data, formula = y ~ x1 + x2 + x1*x2, model = "within", index = c("grp", "year")))

Error: ~does not appear to be a one- or two-sided formula.
y does not appear to be a one- or two-sided formula.
x1 + x2 + x1 * x2 does not appear to be a one- or two-sided formula.
Backtrace:

  1. interactions::interact_plot(...)
  2. jtools::get_data(model, warn = TRUE, ...)
  3. jtools:::get_lhs(formula)

add Dawson & RIchter's (2006) simple slope difference test

Could you add a function to provide Dawson & RIchter's (2006) simple slope difference test for three-way interactions? The 'pequod' package has this in its "simpleSlope()" function but that package hasn't been updated in a couple of years.

interact_plot geom_ribbon

I am wondering if there is a way to change the geom_ribbon default for confidence intervals in interact_plot ? I would like to have dashed lines instead to illustrate confidence intervals, and not to rely on colors. I think in most social science journals colors are not reproduced in published articles.

simple effects for models with only categorical predictors

cat_plot() allows you to probe interactions betwene categorical predictors. It's not clear to me whether you coulod also do a simple effects analysis (e.g. look at the effect of factor A at each level of factor B) - I can't see a way to do it, but it's a natural compliment to cat_plot(). Any plans to impliment a simple effects function for models with only categorical predictors?

Create confidence interval around johnson-neyman point

Hi Jacob
Thanks for this great package, such a wonderful contribution to me (and others) learning to use R .
Is there a way to identify a confidence interval around the point calculated in the jnplot? Since there is a 95% confidence band around the slope, it should be doable I think, but I am not sure how to get the x-values for that region. Any suggestions?

Different results from sim_slopes & johnson_neyman functions

Any reason why I would get different results from these two functions on the same model?

Here is my code and results for each:
sim_slopes(glm2, pred = parent, modx = friend, johnson_neyman = TRUE)

JOHNSON-NEYMAN INTERVAL
When friend is INSIDE the interval [3.40, 14.03], the slope of parent is p < .05.
Note: The range of observed values of friend is [1.00, 5.00]

johnson_neyman(glm2, pred = parent, modx = friend)
JOHNSON-NEYMAN INTERVAL
The Johnson-Neyman interval could not be found. Is the p value for your interaction term below the specified
alpha?

interact_plot errors with `scale`-ed variables

library(interactions)

iris$Sepal.Length_c <- scale(iris$Sepal.Length, center = TRUE, scale = FALSE)
iris$Sepal.Width_c <- 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)
#> Error: variables 'Sepal.Length_c', 'Sepal.Width_c' were specified with different types from the fit

However this doesn't happen with sim_slopes or johnson_neyman.

sim_slopes(fit, pred = Sepal.Length_c, modx = Sepal.Width_c)
#> JOHNSON-NEYMAN INTERVAL 
#> 
#> When Sepal.Width_c is OUTSIDE the interval [-10.36, -2.05], the slope of
#> Sepal.Length_c is p < .05.
#> 
#> Note: The range of observed values of Sepal.Width_c is [-1.06, 1.34]
#> 
#> SIMPLE SLOPES ANALYSIS 
#> 
#> Slope of Sepal.Length_c when Sepal.Width_c = -0.44 (- 1 SD): 
#> 
#>   Est.   S.E.   t val.      p
#> ------ ------ -------- ------
#>   1.53   0.10    14.78   0.00
#> 
#> Slope of Sepal.Length_c when Sepal.Width_c =  0.00 (Mean): 
#> 
#>   Est.   S.E.   t val.      p
#> ------ ------ -------- ------
#>   1.75   0.06    27.64   0.00
#> 
#> Slope of Sepal.Length_c when Sepal.Width_c =  0.44 (+ 1 SD): 
#> 
#>   Est.   S.E.   t val.      p
#> ------ ------ -------- ------
#>   1.97   0.09    21.75   0.00

johnson_neyman(fit, pred = Sepal.Length_c, modx = Sepal.Width_c)
#> JOHNSON-NEYMAN INTERVAL 
#> 
#> When Sepal.Width_c is OUTSIDE the interval [-10.36, -2.05], the slope of
#> Sepal.Length_c is p < .05.
#> 
#> Note: The range of observed values of Sepal.Width_c is [-1.06, 1.34]

Created on 2020-03-13 by the reprex package (v0.3.0)

Document `modx.values` better

Thanks to a question from Jakub Lysek, I've learned that a key feature of modx.values isn't documented: That you can specify the exact values of modx rather than one of the presets ("plus-minus","terciles")

Simslopes: "Error: One of the requested columns does not exist."

Hi,

I have used the interactions package for a while and thank you very much for all the work you put into it. At the moment I am encountering the following issue:

Whereas
interact_plot(model_social, pred = online, modx = target)
works beautifully,
sim_slopes(model_social, pred = online, modx = target)
produces the error
`Error: One of the requested columns does not exist.
Backtrace:

  1. interactions::probe_interaction(...)
  2. interactions::sim_slopes(...)
  3. jtools:::summ.merMod(...)
  4. jtools:::create_table(...)
    In addition: Warning message:
    Johnson-Neyman intervals are not available for factor moderators.`

"Online" is a continuous variable whereas "target" is a factor.

Please let me know if you would like me to provide further information about this case.

Best,
J.

Remove interaction legend

Is your feature request related to a problem? Please describe.

I don't see a way to remove the legend (the moderating variable) in an interact_plot.

Describe the solution you'd like

is it possible to have an argument to entirely remove the legend in interact_plots?

Describe any alternatives or other implementations that you might know of

Additional context

specifying robust standard errors

Hi,

I'm updating my R textbook, and thinking of using interactions within it.
I've been trying to specify robust standard errors. The help file implies (to me at least) that you either set robust = TRUE to get HC3 or set it to the estimator you want (e.g., robust = "HC4"). Have I interpretted that correctly?

Look at the (reprex) code below. I use the following:

default (robust = FALSE)
robust = TRUE
robust = "HC3"
robust = "HC4"

All yield the same standard errors except for robust = TRUE
This makes me think I have misinterpretted the help files. If so, how do I change the estimator?

Thanks for the great package,,

andy

PS the link to this page from https://interactions.jacob-long.com/ is broken

## Load data and centre variables

vids_tib <- readr::read_csv("http://milton-the-cat.rocks/home/data/r_data/video_games.csv") %>% 
  dplyr::mutate(
    caunts_cent = caunts - mean(caunts, na.rm = TRUE),
    vid_game_cent = vid_game - mean(vid_game, na.rm = TRUE)
  )

## Fitting the main model

aggress_lm <- lm(aggress ~ caunts_cent + vid_game_cent + caunts_cent:vid_game_cent, data = vids_tib)

## Simple slopes non-robust SEs

interactions::sim_slopes(
  aggress_lm,
  pred = vid_game_cent,
  modx = caunts_cent,
  confint = TRUE
  )

## Simple slopes robust SEs

interactions::sim_slopes(
  aggress_lm,
  pred = vid_game_cent,
  modx = caunts_cent,
  robust = TRUE,
  confint = TRUE
  )

## Simple slopes HC3 specified

interactions::sim_slopes(
  aggress_lm,
  pred = vid_game_cent,
  modx = caunts_cent,
  robust = "HC3",
  confint = TRUE
  )

## Simple slopes HC4 specified

interactions::sim_slopes(
  aggress_lm,
  pred = vid_game_cent,
  modx = caunts_cent,
  robust = "HC3",
  confint = TRUE
  )

Error probe_interaction when model includes 2 interaction terms with non-numeric variable.

Dear Jacob, I encounter a problem when attempting to plot the interaction terms (both significant) of the following model:

model1_aov <- lmer(value ~ (Group+Stimtype+Trait) + (Group:Trait) + (Stimtype:Trait) + (1|subjectid), mydata)

probe_interaction(model1_aov, pred = Trait, modx = Stimtype, plot.points = TRUE, y.label = "Rating",
alpha = .05, interval = TRUE, int.type = "confidence", int.width = 0.95, color.class="Rainbow")

The issue being that, the visualized slopes don't match the values given by the simple slopes analysis. See for example the figure below. The simple slopes analysis gives a negative value of -0.03 for the slope of Trait when Stimtype = HS, but the visualized slope (red line) is positive.

image

The issue seems related to one of the recent bug fixes, but is slightly different in that it involves two interaction terms instead of a covariate: 'interact_plot, cat_plot, and effect_plot would have errors when the models included covariates (not involved in the interaction, if any) that were non-numeric. That has been corrected. (#41)'

Any solution would be most welcome.

Re-Label Axis and data points in Johnson-Neyman Plot

Hello,
I'm attempting to re-label the axes for a plot I made in R studio, but am having some trouble figuring out exactly how to do so. Apologies if this is in the packages section of R, and I just missed it. I'm still somewhat new to R.

I used the following code to create my plot:
johnson_neyman(model, pred, modx, vmat = NULL, alpha = 0.05,
plot = TRUE, control.fdr = FALSE, line.thickness = 0.5,
df = "residual", digits = getOption("jtools-digits", 2),
critical.t = NULL, sig.color = "black", insig.color = "grey",
mod.range = NULL, title = "Johnson-Neyman plot")

But I would like to know if there's an easy way to re-labeling my predictor variable and modx variable as I was hoping to use these plots in the paper I'm submitting for publication.

Additionally, my modx variable is children's age - centered. So I was wondering if there's a way to also re-label those numbers so they don't show up as -1, 0, 1, etc. but as the actual ages they represent.

Many thanks for any help you're able to offer!

double legend is plotted

Hi team,
When using interact_plot double legend is plotted when using modx and legend.main
interact_plot(lm(log.10.analyte ~ numeric.variable1 * numeric.variable2, data = total_DB_plot), pred = numeric.variable1, modx = numeric.variable2, plot.points = TRUE, jitter = 0.125, # point.shape = TRUE x.label = "Name for variable 1", y.label = "Hg (\u03BCg Hg/L), log10", legend.main = "Name for variable 2", interval = TRUE, int.width = 0.8, color.class = "Blues", point.size = 2, point.shape = 19, facet.modx = FALSE, modx.labels = NULL, modx.values = NULL)

Conditional intercepts

Setting cond.int = TRUE in probe_interaction when x is non-centred results in mismatching intercepts (i.e., console output from sim_slopes does not match plot output from interact_plot). This can be corrected by also setting centered = "none", but should probably be corrected or should print a warning for users who may not realise.

Reproducible example:

##### THIS IS OKAY -- x has already been centred beforehand

set.seed(0)
data1 = data.frame(x = scale(rnorm(20), center = TRUE), m = scale(rnorm(20), center = TRUE))
data1$y = 5 * data1$x * data1$m + rnorm(20)

res1 = lm(y ~ x*m, data = data1)
summary(res1)
# based on manual calculations
# when m at -1sd, int =  0.41, slope = -4.78
# when m at mean, int = -0.11, slope =  0.08
# when m at +1sd, int = -0.62, slope =  4.94

interactions::probe_interaction(res1, pred = x, modx = m, cond.int = TRUE)
# matches manual calculations

##### THIS IS NOT OKAY -- x has not been centred beforehand

set.seed(0)
data2 = data.frame(x = sample(c(0,1), 20, replace = TRUE), m = scale(rnorm(20), center = TRUE))
data2$y = 5 * data2$x * data2$m + rnorm(20)

res2 = lm(y ~ x*m, data = data2)
summary(res2)
# based on manual calculations
# when m at -1sd, int = -0.33, slope = -4.17
# when m at mean, int = -0.18, slope =  0.32
# when m at +1sd, int = -0.03, slope =  4.81

interactions::probe_interaction(res2, pred = x, modx = m, cond.int = TRUE)
# wrong cond ints in sim_slopes output but correct in interact_plot graph

interactions::probe_interaction(res2, pred = x, modx = m, cond.int = TRUE, centered = "none")
# correct cond ints

Issue with cat_plot pred.values

Hi, there seems to be an issue with the pred.values option of cat_plot.

Firstly, although the factor I'm using is not ordered alphabetically, it is displaying so in the resulting interaction graph. I tried to resolve this using the pred.values option, yet this did not work. I also tried to select only certain values of pred, yet it still returns all of them. Wondering if it was just me, I switched the modx and pred variables, and tested it with modx.values option, which worked both to reorder the categories appearance, and to select only specific categories to show. Additionally, the modx.values option recognizes the factor order, rather than presenting it in alphabetical order. I also found in perhaps some older documentation, a predvals option, which I tried and also did not work. Neither are returning an error, it just seems that the option is not working as it should.

I wonder if you could look into this?

Many thanks!

Problems with plot.sim_slopes

I'm having a problem with plot.sim_slopes. The plot has a few issues. First, the x-axis scale is kind of wild and it's not clear how to fix that (maybe through a digits argument?). Second, it's unclear why my confidence intervals are not symmetric around the point estimate, even though they are in the sim_slopes output. Below is an example using data from cobalt.

library("interactions")
data("lalonde", package = "cobalt")

fit <- lm(re78 ~ treat * race, data = lalonde)
plot(sim_slopes(fit, pred = "treat", modx = "race"))
#> Warning: Johnson-Neyman intervals are not available for factor moderators.

Created on 2019-05-28 by the reprex package (v0.3.0)

Interaction plot resolution

Trying to increase resolution of interaction simple slope plots but can't seem to get anything different than 96 dpi when using probe_interaction.

Any ideas?

Error in .subset2

I'm having trouble using the interact_plot() function. The following command used to work correctly when this function was part of jtoolspackage:

interact_plot(model2, pred = Africana, modx = tipo, interval = T, robust = "HC1")

But now I get this error:

Error in .subset2(x, i, exact = exact) : invalid subscript type 'symbol'

This is the model summary:

> summary(model2)

Call:
lm(formula = H2.inmigracion, data = p@data)

Residuals:
     Min       1Q   Median       3Q      Max 
-17.3044  -1.1706  -0.1362   0.9745  17.0160 

Coefficients:
                                                      Estimate  Std. Error t value           Pr(>|t|)    
(Intercept)                                         5.88028187  0.38103225  15.433            < 2e-16 ***
renta_disponible_media16                            0.00005651  0.00001435   3.939 0.0000827893452961 ***
tipoZona de densidad intermedia                    -0.74167836  0.19023050  -3.899 0.0000977235555040 ***
tipoCiudades                                       -1.51741257  0.26711938  -5.681 0.0000000140570307 ***
alquiler                                           -0.01124921  0.00352482  -3.191           0.001423 ** 
Africana                                            0.15533060  0.02790134   5.567 0.0000000270340785 ***
masde64                                            -0.05929514  0.00298283 -19.879            < 2e-16 ***
VOX15                                               0.76708174  0.05843900  13.126            < 2e-16 ***
derecha                                             0.13950679  0.00398449  35.012            < 2e-16 ***
izquierda                                          -0.07595612  0.00428095 -17.743            < 2e-16 ***
paro.hom                                           -0.14380445  0.02347032  -6.127 0.0000000009527316 ***
paro.hom.diff06.18                                  0.14928709  0.04180212   3.571           0.000358 ***
tipoZona de densidad intermedia:paro.hom.diff06.18  0.22277924  0.04830963   4.611 0.0000040820913076 ***
tipoCiudades:paro.hom.diff06.18                     0.48334043  0.06332275   7.633 0.0000000000000266 ***
tipoZona de densidad intermedia:Africana           -0.00419771  0.02891354  -0.145           0.884573    
tipoCiudades:Africana                              -0.17692442  0.03016461  -5.865 0.0000000047257359 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.999 on 5918 degrees of freedom
  (6 observations deleted due to missingness)
Multiple R-squared:  0.6372,	Adjusted R-squared:  0.6362 
F-statistic: 692.8 on 15 and 5918 DF,  p-value: < 2.2e-16

And this is my sessionInfo():

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/C/es_ES.UTF-8/es_ES.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] jtools_2.0.0    readxl_1.2.0    spdep_0.8-1     spData_0.3.0    Matrix_1.2-15   raster_2.8-19   sp_1.3-1        forcats_0.3.0  
 [9] stringr_1.4.0   dplyr_0.8.0     purrr_0.3.0     readr_1.3.1     tidyr_0.8.2     tibble_2.0.1    ggplot2_3.1.0   tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0         lubridate_1.7.4    lattice_0.20-38    deldir_0.1-16      zoo_1.8-4          gtools_3.8.1       assertthat_0.2.0  
 [8] R6_2.4.0           cellranger_1.1.0   plyr_1.8.4         backports_1.1.3    stats4_3.4.1       coda_0.19-2        httr_1.4.0        
[15] pillar_1.3.1       rlang_0.3.1        lazyeval_0.2.1     rstudioapi_0.9.0   gdata_2.18.0       gmodels_2.18.1     splines_3.4.1     
[22] rgdal_1.3-6        munsell_0.5.0      broom_0.5.1        compiler_3.4.1     modelr_0.1.3       xfun_0.4           pkgconfig_2.0.2   
[29] tidyselect_0.2.5   expm_0.999-3       codetools_0.2-16   crayon_1.3.4       withr_2.1.2        MASS_7.3-51.1      grid_3.4.1        
[36] nlme_3.1-137       jsonlite_1.6       gtable_0.2.0       huxtable_4.3.0     magrittr_1.5       scales_1.0.0.9000  cli_1.0.1         
[43] stringi_1.3.1      LearnBayes_2.15.1  xml2_1.2.0         generics_0.0.2     boot_1.3-20        sandwich_2.5-0     tools_3.4.1       
[50] glue_1.3.0         hms_0.4.2          yaml_2.2.0         colorspace_1.4-0   rvest_0.3.2        knitr_1.21         haven_2.0.0       
[57] interactions_1.0.0

Error in xj[i] : invalid subscript type 'list'

I tried replicating this in example data with no luck. So, clearly my data is acting funky that the example survey data does not.

datamod2 <- read.csv("interactionsdata.csv")
#datamod2<- datamod2[complete.cases(datamod2), ] Desperate ideas, no difference.
library(survey)
library(interactions)
anes_design_mod2 <-
  svydesign( 
    ~psu , 
    strata = ~strata, 
    data = datamod2, 
    weights = ~weight, 
    nest = TRUE 
  )

#Try it both with binomial 
model6 <- svyglm(wiretapnowarrant ~ tthreat.c*poliknow.c*auth.both.t.c +
                          republican + independent + male + age.c + rfinc + education + race + muslim_thermo.c,
                        family="binomial",
                        na.action=na.omit, 
                        anes_design_mod2)
#And quasi-binomial
model6b <- svyglm(wiretapnowarrant ~ tthreat.c*poliknow.c*auth.both.t.c +
                            republican + independent + male + age.c + rfinc + education + race + muslim_thermo.c,
                          family="quasibinomial", 
                          na.action=na.omit,
                          anes_design_mod2)

summ(model6)
sim_slopes(model6, pred = tthreat.c, modx = poliknow.c, mod2 = auth.both.t.c)
typeof(datamod2$tthreat.c)
typeof(datamod2$poliknow.c)
typeof(datamod2$auth.both.t.c)
sim_slopes(model6b, pred = tthreat.c, modx = poliknow.c, mod2 = auth.both.t.c)

Can't upload the data via github so a dropbox link for it provided here:
https://www.dropbox.com/s/xvjn1xdwmyy6b94/interactionsdata.csv?dl=0

Unable to extract deviance function

I'm running into an issue when conducting simple slopes analysis on a lmer( model.

Warning message:
"Johnson-Neyman intervals are not available for factor moderators."
Error in lmerTest::as_lmerModLmerTest(model): Unable to extract deviance function from model fit
Traceback:

1. sim_slopes(model = Diversity.mod5, pred = Responsiveness, modx = Status)
2. summ(newmod, model.fit = FALSE, confint = TRUE, ci.width = ci.width, 
 .     vifs = FALSE, which.cols = which.cols, pvals = pvals, vcov = covmat, 
 .     ...)
3. summ.merMod(newmod, model.fit = FALSE, confint = TRUE, ci.width = ci.width, 
 .     vifs = FALSE, which.cols = which.cols, pvals = pvals, vcov = covmat, 
 .     ...)
4. get_all_sat(model)
5. lmerTest::as_lmerModLmerTest(model)
6. stop("Unable to extract deviance function from model fit")

Is there a version issue?

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] interactions_1.1.3 lme4_1.1-23        Matrix_1.2-18      arrow_1.0.1       

loaded via a namespace (and not attached):
 [1] tidyr_1.1.0         bit64_0.9-7         jsonlite_1.7.0     
 [4] splines_4.0.2       foreach_1.5.0       tmvnsim_1.0-2      
 [7] modelr_0.1.8        assertthat_0.2.1    statmod_1.4.34     
[10] pander_0.6.3        bayestestR_0.7.2    numDeriv_2016.8-1.1
[13] pillar_1.4.6        backports_1.1.7     lattice_0.20-41    
[16] glue_1.4.1          jtools_2.1.0        uuid_0.1-4         
[19] digest_0.6.25       RColorBrewer_1.1-2  minqa_1.2.4        
[22] colorspace_1.4-1    sandwich_2.5-1      plyr_1.8.6         
[25] htmltools_0.5.0     pkgconfig_2.0.3     broom_0.7.0        
[28] purrr_0.3.4         xtable_1.8-4        mvtnorm_1.1-1      
[31] scales_1.1.1        emmeans_1.4.8       tibble_3.0.3       
[34] farver_2.0.3        generics_0.0.2      ggplot2_3.3.2      
[37] sjlabelled_1.1.6    ellipsis_0.3.1      TH.data_1.0-10     
[40] repr_1.1.0          cli_2.0.2           mnormt_2.0.1       
[43] survival_3.1-12     magrittr_1.5        crayon_1.3.4       
[46] effectsize_0.3.1    estimability_1.3    evaluate_0.14      
[49] GGally_2.0.0        fansi_0.4.1         doParallel_1.0.15  
[52] nlme_3.1-148        MASS_7.3-51.6       tools_4.0.2        
[55] lifecycle_0.2.0     multcomp_1.4-13     munsell_0.5.0      
[58] ggeffects_0.15.0    compiler_4.0.2      rlang_0.4.7        
[61] grid_4.0.2          nloptr_1.2.2.2      pbdZMQ_0.3-3       
[64] iterators_1.0.12    IRkernel_1.1.1.9000 parameters_0.8.0   
[67] labeling_0.3        base64enc_0.1-3     boot_1.3-25        
[70] lmerTest_3.1-2      gtable_0.3.0        codetools_0.2-16   
[73] reshape_0.8.8       abind_1.4-5         sjstats_0.18.0     
[76] sjmisc_2.8.5        R6_2.4.1            zoo_1.8-8          
[79] knitr_1.29          dplyr_1.0.0         performance_0.4.7  
[82] optimx_2020-4.2     bit_1.1-15.2        insight_0.9.0      
[85] parallel_4.0.2      IRdisplay_0.7.0     Rcpp_1.0.5         
[88] vctrs_0.3.2         tidyselect_1.1.0    xfun_0.15          
[91] coda_0.19-3        

interact_plot point color

Hello
I have been using interact_plot to plot 2- and 3-way interactions between continuous variables.
The documentation notes that when turning on plot.points: "The color of the dots will be based on their moderator value"
But it appears that the points are always the color of the higher value of the moderator (+1 SD/ upper tercile). It is possible to change this color so that reflects the moderator value?
thanks!

outcome.scale argument problem

Thank you for the package!

I use the interact_plot function to plot an interaction between a categorical (binary) and a continuous predictor (centered and scaled), from a glmer model. I want the outcome variable to be plotted on the link scale, so I write outcome.scale="link". This used to work when this function was in the jtools package but now it doesn't change anything on the plot (the lines are still curvy, not straight), nor it gives an error. It's just still on the original scale.

Any idea why?

sim_slopes(): Error with ordered factors

I have a model with an interaction between a continuous predictor and an ordered factor predictor.

The sim_slopes() function gives the following error:
Error in relevel.ordered(dt[[modx]], ref = as.character(modxvals2[i])) : 'relevel' only for unordered factors

I was able to make it work by changing the lines of your code where you handle non-numeric modx/mod2 by adding ordered = F to the factor line.

Original:

else {
        dt[[modx]] <- factor(dt[[modx]])
        dt[[modx]] <- relevel(dt[[modx]], ref = as.character(modxvals2[i]))
        dt[[modx]] <- stats::C(dt[[modx]], "contr.treatment")
      }

Fix:

else {
        dt[[modx]] <- factor(dt[[modx]], ordered = F)
        dt[[modx]] <- relevel(dt[[modx]], ref = as.character(modxvals2[i]))
        dt[[modx]] <- stats::C(dt[[modx]], "contr.treatment")
      }

And same for mod2.

I would be curious to see if you think this will cause bad results, and if not perhaps it can be implemented? I'm guessing that the ordering doesn't matter for simple slopes.

Interactions with glm poisson

Does this package work with a glm poisson model? I receive this error This could cause incorrect results if data has been altered since the model was fit. You can manually provide the data to the "data =" argument.

When I enter the data argument, then it just repeats the same error.

sim_slopes error (non-numeric argument to binary operator)

Hi Jacob

Love using your package(s)!
I just updated the 'interaction' package (via CRAN on 9th of May) and was re-running some old analyses. They now give me the following error, when trying to calculate simple slopes of an interaction in a merMod class model. Also tried it with some random test data and get the same results.
Code I used:
mod_model <- lmer(DV~IV*mod + (1|group), data=dat)
sim_slopes(mod_model, pred=IV, modx = mod)
Output:
Error in y3^2 : non-numeric argument to binary operator

Thanks for looking into it!

point.alpha not working

Hi there,

I've been plotting interactions with data plots showing (plot.points=T). Sometimes I have many overlapping points, and I would like to lower the alpha level of the points with the point.alpha argument. However, the argument doesn't seem to change the plots in any way.

E.g., Unless I'm misunderstanding something, the following code should produce completely transparent points, but I receive the following plot.

library(interactions)
states <- as.data.frame(state.x77)
states$HSGrad <- states$\`HS Grad\`
fit <- lm(Income ~ HSGrad + Murder * Illiteracy, data = states)
interact_plot(model = fit, pred = Murder, modx = Illiteracy,, plot.points = T, point.alpha = .0001)

Screen Shot 2019-08-14 at 14 36 15

Thanks!

cannot change axis labels in sim_slopes

Hi, I was trying to have sim_slopes display correct labels at the request of a reviewer. I cannot seem to find a way to make it work.

My complete label contains more than one word so I changed the variable names before I ran the model and hope to pass them on to sim_slopes() so that I don't need to change labels from this function. When I specify the variable names with escape symbol, "the variable name", an error message is returned:
"Error in [.data.frame(model.frame(model), , modx) :
undefined columns selected"

I wonder how to fix that? this is required before I could submit my revision. any input is appreciated. thank you!

CRAN package for interactions

Hello Jacob. When can we expect this package to be on CRAN? Please let me know if you need help with testing. This is what I currently see when I run my code:
image

cat_plot Error in zero_range(from) : x must be length 1 or 2

I keep getting this error which is maybe coming from gglplot/scales and don't know how to fix it.

My argument call format is
cat_plot(mdl, pred=factor1, modx=factor2, data=mdl.df)

My R version is 3.5.3, interactions 1.1.1, and ggplot2 3.2.1

I don't know if this is something you can fix here but just wanted to let you know.

Tweak usage of vdiffr in tests

This concerns

EpiEstim HaDeX MTLR Quartet RoBMA Ternary TestDimorph TreeDist
TreeTools basf cmstatr colourlovers cowplot crplyr dabestr
descriptr dfoliatR disaggR easyalluvial finbif gamma ggResidpanel
ggcharts ggeasy ggfittext ggformula gggenes gggibbous gghighlight
ggnewscale ggparty ggperiodic ggplot2 ggridges ggstance
ggtext ggthemes ggvoronoi gratia gridtext hagis infer
interactions jpmesh kayadata metR mizer mlr3spatiotempcv
modelsummary moderndive mosaic ormPlot pROC paletteer patchwork
pdqr piecepackr precisely prettyB projections qtl2 survParamSim
tacmagic tidytext treemapify tsvr visdat wsyn

Suggested packages should be used conditionally: see §1.1.3.1 of 
'Writing R Extensions'.  Some of the requirements of vdiffr are hard to 
install on a platform without X11 such as M1 Macs: see the logs at 
https://urldefense.com/v3/__https://www.stats.ox.ac.uk/pub/bdr/M1mac/__;!!KGKeukY!kYnXqmwzyg6mAmzTimuawyhWhSRvDDK5pCZwl7GVgByvmNPi5erDU-2FN50vpjR-zh8$ .

In some cases there are other suggested packages not used conditionally: 
you can check all of them by setting environment variable 
_R_CHECK_DEPENDS_ONLY_=true  -- see 
https://urldefense.com/v3/__https://cran.r-project.org/doc/manuals/r-devel/R-ints.html*Tools__;Iw!!KGKeukY!kYnXqmwzyg6mAmzTimuawyhWhSRvDDK5pCZwl7GVgByvmNPi5erDU-2FN50vzToYI6g$  .

Please correct ASAP and before 2021-01-12 to safely retain the package 
on CRAN.

-- 
Brian D. Ripley,                  [email protected]
Emeritus Professor of Applied Statistics, University of Oxford

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.