Peter Wagey
2020-Sep-19 08:28 UTC
[R] How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?
Hi R users, I was trying to create a figure of three-way-interactions. There is a function "plot-model" but I was wondering whether we can extract the predicted value before we run the "plot-model" function. For example: in this example, plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", "c161sex")) How can we see the predicted values that are used to plot the figure? If we can see the data (predicted values), we could use other functions to create another type of figures. Thank you very much for your suggestions. Thanks, Peter ############# library(sjPlot) library(sjmisc) library(ggplot2) data(efc) theme_set(theme_sjplot()) # make categorical efc$c161sex <- to_factor(efc$c161sex) # fit model with 3-way-interaction fit <- lm(neg_c_7 ~ c12hour * barthtot * c161sex, data = efc) # select only levels 30, 50 and 70 from continuous variable Barthel-Index plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", "c161sex")) How can we get the predicted value that is used to plot the graph? we would like to see the predicted value using three groups of barthtot [30,50,70].Is there any way we can extract the data (predicted value) so that we can use other graphic functions to create figures? [[alternative HTML version deleted]]
Bert Gunter
2020-Sep-19 18:29 UTC
[R] How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?
As no one has responded. Typically,> ?predictso> predict(fit)should give you fitted values for the class of fit, whatever it is. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Sep 19, 2020 at 1:29 AM Peter Wagey <peter.wagley09 at gmail.com> wrote:> Hi R users, > I was trying to create a figure of three-way-interactions. There is a > function "plot-model" but I was wondering whether we can extract the > predicted value before we run the "plot-model" function. > For example: > in this example, > plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", > "c161sex")) > How can we see the predicted values that are used to plot the figure? If we > can see the data (predicted values), we could use other functions to create > another type of figures. > Thank you very much for your suggestions. > > Thanks, > > Peter > ############# > library(sjPlot) > library(sjmisc) > library(ggplot2) > data(efc) > theme_set(theme_sjplot()) > > # make categorical > efc$c161sex <- to_factor(efc$c161sex) > > # fit model with 3-way-interaction > fit <- lm(neg_c_7 ~ c12hour * barthtot * c161sex, data = efc) > > # select only levels 30, 50 and 70 from continuous variable Barthel-Index > plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", > "c161sex")) > > How can we get the predicted value that is used to plot the graph? we would > like to see the predicted value using three groups of barthtot > [30,50,70].Is there any way we can extract the data (predicted value) so > that we can use other graphic functions to create figures? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Paul Bivand
2020-Sep-28 13:41 UTC
[R] How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?
If you read ?plot_model() there is a description of type="pred" that suggests fuller details are found under ?ggeffect() from the ggeffects package. This in turn suggests that if you use 'ggpredict()' with arguments that replicate those you used in plot_model(), you get a data.frame with the values that get passed to plot_model(). As these functions can handle many different fitted models, the help pages are large and have subsections for different model classes. However, the information requested is (as is not uncommon) in the help pages. Paul Bivand On Sat, 19 Sep 2020 at 19:30, Bert Gunter <bgunter.4567 at gmail.com> wrote:> > As no one has responded. Typically, > > ?predict > so > > predict(fit) > should give you fitted values for the class of fit, whatever it is. > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sat, Sep 19, 2020 at 1:29 AM Peter Wagey <peter.wagley09 at gmail.com> > wrote: > > > Hi R users, > > I was trying to create a figure of three-way-interactions. There is a > > function "plot-model" but I was wondering whether we can extract the > > predicted value before we run the "plot-model" function. > > For example: > > in this example, > > plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", > > "c161sex")) > > How can we see the predicted values that are used to plot the figure? If we > > can see the data (predicted values), we could use other functions to create > > another type of figures. > > Thank you very much for your suggestions. > > > > Thanks, > > > > Peter > > ############# > > library(sjPlot) > > library(sjmisc) > > library(ggplot2) > > data(efc) > > theme_set(theme_sjplot()) > > > > # make categorical > > efc$c161sex <- to_factor(efc$c161sex) > > > > # fit model with 3-way-interaction > > fit <- lm(neg_c_7 ~ c12hour * barthtot * c161sex, data = efc) > > > > # select only levels 30, 50 and 70 from continuous variable Barthel-Index > > plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]", > > "c161sex")) > > > > How can we get the predicted value that is used to plot the graph? we would > > like to see the predicted value using three groups of barthtot > > [30,50,70].Is there any way we can extract the data (predicted value) so > > that we can use other graphic functions to create figures? > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.