sammo3182 / interplot Goto Github PK
View Code? Open in Web Editor NEWinterplot: plotting interactive effects
License: Other
interplot: plotting interactive effects
License: Other
In several places the package sets a seed in the interplot()
function, e.g. here:
interplot/R/Interplot_default.R
Line 66 in 4050557
This is bad practice because you interfere with the user-set seed. Example:
set.seed(42)
data(mtcars)
m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
interplot(m = m_cyl, var1 = 'cyl', var2 = 'wt')
rnorm(1)
gives the same random number as
set.seed(43)
data(mtcars)
m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
interplot(m = m_cyl, var1 = 'cyl', var2 = 'wt')
rnorm(1)
which shouldn't be the case.
glm generates objects that have two classes: “glm” and “lm”. So R is complaining that we’re asking it to compare two things (on the left of the equation) with one thing (on the right of the equation)
From Prof. Matthias Gehrke
the column names in the dataframe returned by interplot should be exchanged. First column should be name of var1, second column values_in_var2. Now it is name of var2 and values_in_var1.
From Guan Wang by email
I ran the example based on the mtcars dataset
provided in the R file (https://cran.r-project.org/web/packages/interplot/vignettes/interplot-vignette.html). The two variables in the interaction term are "wt (continuous)" and "vs (binary)". Below is the code:
library(interplot)
data(mtcars)
class(mtcars$vs);table(mtcars$vs)
m_cyl <- glm(am ~ wt * vs, data = mtcars,family = binomial(link = "logit"))
summary(m_cyl)
windows()
plot_1 <- interplot(m_cyl, var1 = "wt",var2 = "vs",
predPro = TRUE,
var2_vals = c(0,1))
plot_1
windows()
plot_2 <- interplot(m_cyl, var1 = "vs",var2 = "wt",
predPro = TRUE,
var2_vals = c(min(mtcars$wt),max(mtcars$wt)))
plot_2###
@fsolt The package passed the check once, but producing the following errors in the recheck.
The file "'interplot-Ex.R" including the 'hello' function was created by the checking process.
No idea what happens here.
* checking examples ... ERROR
Running examples in 'interplot-Ex.R' failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: hello
> ### Title: Hello, World!
> ### Aliases: hello
>
> ### ** Examples
>
> hello()
Error: could not find function "hello"
Execution halted
* DONE
Status: 1 ERROR, 2 WARNINGs
See
'E:/MEGAsync/Dropbox/01_Instruction/Research/R packages/interplot.Rcheck/00check.log'
for details.
checking examples ... ERROR
Running examples in 'interplot-Ex.R' failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: hello
> ### Title: Hello, World!
> ### Aliases: hello
>
> ### ** Examples
>
> hello()
Error: could not find function "hello"
Execution halted
checking for code/documentation mismatches ... WARNING
Functions or methods with usage in documentation object 'hello' but not in code:
hello
Dear @sammo3182,
Thanks for responding to my earlier question about the confidence interval of the difference between the conditions that is printed below the plot. I want to suggest to save this confidence interval as a numeric value in the interplot output. I needed these numbers for a large set of models, and i ended up extracting it from the string in interplot.model$label$caption, which is a bit clunky. Maybe there was a better way?
I also have a number of models using categorical variables. Currently, you don't print the ci's of the differences between the categories (well, there is a ci, but it's not correct). Currently in interplot_default.R lines 249-257 are commented out. I wonder about the problem here: is this way of calculating CI's of the difference wrong or is there another problem - like with plotting these CI's.
Best, Gijs
Really like this package! However, despite my attempts I cannot get the "var2_vals" to function as expected and continue to get the error:
Error in data.matrix(fake_data) %*% t(data.matrix(m.sims@coef)) :
non-conformable arguments
the code I am using is
p1 <- interplot(m = glm.int.red, var1 = "rts", var2 = "age", predPro = TRUE,
var2_vals = seq(10, 60, by=10) , sims=5000, ci=0.95)
p1
the glm with the interaction executes as desired...
glm.int.red <- glm(formula = cbind(surv, 1 - surv) ~ as + ds + es + fs + hs +
iss + rts + age + bp + as:es + as:hs + as:rts + as:bp + ds:fs +
ds:age + ds:bp + es:hs + es:rts + fs:iss + fs:age + hs:age +
iss:bp + age:rts, family = binomial(link = "logit"), data = trauma)
Please help as I would really like to plot these interactions...
particularly the false-positive-rate confidence intervals
https://cran.r-project.org/web/packages/plotMElm/index.html
This is really a great package! However, linear panel models from the plm package are up until now not supported, right? Is there a workaround to use the data of plm objects in interplot? Thank you for your efforts!
In vignettes/interplot-vignette.Rmd, plots included in the manuscript do not include any axes labels raising concerns about the user friendliness of the implementation.
Here are the sample codes that need to add axes labels:
interplot(m = m_cyl, var1 = "cyl", var2 = "wt")
interplot(m = m_cyl, var1 = "wt", var2 = "cyl")
interplot(m = m_cyl, var1 = "wt", var2 = "cyl", ci = .9, point = T)
Encountered an issue:
interplot(model1, var1 = "var1",
var2 = "var2",
predPro = TRUE,
var2_vals = c(0,1))
Warning message:
funs()
was deprecated in dplyr 0.8.0.
Please use a list of either functions or lambdas:
Simple named list: list(mean = mean, median = median)
Auto named with tibble::lst()
: tibble::lst(mean, median)
Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
The deprecated feature was likely used in the interplot package.
First off, thanks for the great package! It's really useful, especially after including histograms to evaluate the data distribution of the interacting variable.
One quick thought: would it be possible to provide a custom variance-covariance matrix for the regression coefficients? This would be useful in implementing robust standard errors, for instance with the sandwich
package or Frank Harrell's rms
package. (I know, robust SEs have issues, but sometimes reviewers demand them...).
Anton Strezhnev's excellent interaction_plot_continuous()
function provides, for instance, a varcov =
option, which allows one to provide custom variance-covariance matrices.
Attempting to install the github version of interplot I got the following error:
Downloading github repo twitter/BreakoutDetection@master
Error in system(full, intern = quiet, ignore.stderr = quiet, ...) :
error in running command
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS
...
Searching for this error, I found a workaround on RevolutionAnalytics/RRO#37:
To work around this issue, set options(unzip = 'internal') before calling install_github. (See #37 and r-lib/devtools#406 )
After running the following, the github installation works as expected.
options(unzip = 'internal')
devtools::install_github("sammo3182/inrerplot")
Thanks for the great tool! I'm planning to use this tool along with GEE model but it seems there is no support for that the moment. That would be a great feature to have!
The methods defined are unclear given the code and its comments which has:
method for class 'data.frame' :
interplot.plot <- function(...)
method for class 'lm' and 'glm' :
interplot.default <- function(...)
The generic function method is also confusing and seems error prone / not compatible with the different classes and methods systems in R as well as class inheritance.
I haven't studied it enough to be sure, but a quick glance looks like the code was repeated across all the subfunctions. Having the factor code in a separate function would both make it easier to further revise as well as keep the main code more legible.
Hello,
I am running some glm models with a complex survey design data using the "survey" package. The resulting object is labeled a "svyglm" and the interplot function doesn't seem to be liking the object type. I'm curious if these models are not supported on purpose or if you plan on supporting them. Here is the error I receive when I try to plot the interaction
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘sim’ for signature ‘"svyglm"’
Thanks,
Daniel
http://rpubs.com/kohske/dual_axis_in_ggplot2 is a bit of a start
Thank Dr. Rachel Bernhard to bring this issue to us. The idea is basically presenting conditional effects based on the same conditioning variables at different categories. It can be more user-friendly if there's a special argument for that.
In addition: Warning message: replacing previous import ‘dplyr::combine’ by ‘gridExtra::combine’ when loading ‘dotwhisker’
Suggestion from Professor Wanlu Deng:
Conduct simulations of three types of true models:
only possible (if at all) for flat models
I just fixed a couple of major bugs, Hu
and a brief discussion of use of interaction terms to README
Issue about S4 class for predPro
library(lme4)
m1 <- glmer(vs ~ mpg * wt + (1 | cyl), mtcars, family=binomial(link="logit"))
library(interplot)
interplot(m1, var1 = "mpg",var2 = "wt", predPro = TRUE, var2_vals = c(1.513, 5.424))
Output:
Error: $ operator not defined for this S4 class
Refer to interflex
Would it be possible to extend interplot to ivreg
objects? I get an error when I try to run this due to the fact that arm::sim
does not work with ivreg
models. Extracting the second regression from the 2SLS and running the plot on that alone "works", but standard errors are misleading here. I can patch something together for my particular application but I think there might be more general interest in this functionality.
In your vignette, you state that interplot "plots the changes in the coefficient of one variable in a two-way interaction term conditional on the value of the other included variable." In each example provided, only two variables are included as independent variables (or a single variable with a quadratic). How does your package accommodate multiple regression with more variables than those involved in the interaction(s) of interest? Particularly, at what values does the package condition 'controls' in computing marginal effects? Lastly, do the methods for nonlinear models account for the inherent interdependence among variables?
Interaction with factors will be automatically converted to interactions with binaries, but with different var2 name.
A potential solution: using caret::dummyVars
to break the factor into dummies ahead and plot each dummy interaction in a facet.
per Levi Littvay (via Twitter DM):
the interplot manual could use a bit of tweaking. mitools is not even mentioned until interplot.mlmmi. No word under interplot.lmmi. Then I was a shocked to find out that these are not even functions, all just part of the mitools command. And an example under each section (impute, run the model, draw) would really make everything more user friendly.
In vignettes/interplot-vignette.Rmd, if one could avoid loading all these packages ( ggplot2/abind/arm/MASS/Matrix/lme4) by moving some dependencies to imports.
When running the build_vignettes
function, it returns NULL. No way to update vignette now.
interplot(iris)
gives an error
Error in geom_line()
:
! Problem while computing aesthetics.
Error occurred in the 1st layer.
Caused by error in FUN()
:
! object 'fake' not found
which is not very informative.
cf #42 for dotwhisker
example code in dev folder
Hi.
Thanks for the very useful package. I just tried to adjust the color. Without hist=T
everything works fine.
m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
interplot(m = m_cyl, var1 = "cyl", var2 = "wt", color="green")
When adding histograms, coloring seems to be impossible...
interplot(m = m_cyl, var1 = "cyl", var2 = "wt", color="green", hist=T)
How can I color the line and still add histograms?
Thanks
interplot(m1, "v1", "v2) doesn't work for glmerMod objects because it goes to .default; interplot:::interplot.glmerMod(m1, "v1", "v2) works, so the bug comes before that
Since recently the interplot function prints a confidence interval (numerically) in the bottom right corner of the interaction plot, e.g. CI(Max-Min): [number,number]. How do I remove this? Looking into the code the ci_diff value regulates this, but I don't know what value to give it to stop printing this CI.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.