How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?

Peter Wagey
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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?

Bert Gunter-2
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 <[hidden email]>
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]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?

Paul Bivand
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 <[hidden email]> 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 <[hidden email]>
> 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]]
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.