Backtransforming response for plotting allEffectsbacktransform `scale()` for plottingPlot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?Save plot to image file instead of displaying it using Matplotlibvisreg plot binomial distributionCannot run glmer models with na.action=na.fail, necessary for MuMIn dredge functionMeaning of SE for lsmeans type=“response”ggplot: rescale axis (log) and cut axisCorrect way to scale for multilevel regression using lmer [R]scale on effect plot using GLMScaling predictors in lme4 glmer doesn't resolve eigenvalue warnings; neither does alternative optimization
What is the tangent at a sharp point on a curve?
Extract substring according to regexp with sed or grep
Can a Knock spell open the door to Mordenkainen's Magnificent Mansion?
How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?
Should a narrator ever describe things based on a character's view instead of facts?
New Order #2: Turn My Way
Is this saw blade faulty?
Not hide and seek
Would this string work as string?
Is there a distance limit for minecart tracks?
How would a solely written language work mechanically
How to get directions in deep space?
Capacitor electron flow
Why didn't Voldemort know what Grindelwald looked like?
Derivative of an interpolated function
Relations between homogeneous polynomials
Put the phone down / Put down the phone
What can I do if I am asked to learn different programming languages very frequently?
Do I have to take mana from my deck or hand when tapping this card?
Air travel with refrigerated insulin
Highest stage count that are used one right after the other?
How do I lift the insulation blower into the attic?
Pre-Employment Background Check With Consent For Future Checks
Why is indicated airspeed rather than ground speed used during the takeoff roll?
Backtransforming response for plotting allEffects
backtransform `scale()` for plottingPlot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?Save plot to image file instead of displaying it using Matplotlibvisreg plot binomial distributionCannot run glmer models with na.action=na.fail, necessary for MuMIn dredge functionMeaning of SE for lsmeans type=“response”ggplot: rescale axis (log) and cut axisCorrect way to scale for multilevel regression using lmer [R]scale on effect plot using GLMScaling predictors in lme4 glmer doesn't resolve eigenvalue warnings; neither does alternative optimization
I have fitted a few models using glmer
from thelme4
package and did model selection with MuMIn::dredge()
followed by model averaging. My response is frequency of occurrence of an animal in front of camera traps (continuous, number of photos per 100 hours of camera time); the predictors are minimum distances from a camera trap to landscape categories in meters, sometimes with an interaction with the day phase (day/night).
The response shows Gamma-distribution, but to make the model work I had to transform my response by adding 1, as the Gamma distribution can't handle non-positive data and quite a few of my data points were zeros as shown in this histogram:
Also, I had to scale the predictors, otherwise I got convergence warnings like
Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
I did this with scale(..., center = TRUE)
.
My model formula looks like this:
mod <- glmer(Species_Frequency ~ scaled_Minimal_Distance1 +
scaled_Minimal_Distance2 +
(scaled_Minimal_Distance3 * Dayphase),
data = data,
na.action = na.fail,
family = Gamma(link = "log"),
control = glmerControl(optimizer = "bobyqa"))
Now I want to plot the results of mod
using plot(allEffects(mod))
.
For plotting, I am backscaling my predictors in the allEffects
-object by accessing
allEffects(mod)[["scaled_Minimal_Distance1"]][["x"]][["scaled_Minimal_Distance1"]]
and doing as shown Here. I would also like to back-transform my response, to make the plot more understandable. Otherwise one would always have to keep in mind that 1 on the y-axis is actually 0, 2 is 1 etc. Can someone help me on how to do this, as I hit a roadblock and can't seem to figure it out myself.
Thank you very much in advance.
r plot
add a comment |
I have fitted a few models using glmer
from thelme4
package and did model selection with MuMIn::dredge()
followed by model averaging. My response is frequency of occurrence of an animal in front of camera traps (continuous, number of photos per 100 hours of camera time); the predictors are minimum distances from a camera trap to landscape categories in meters, sometimes with an interaction with the day phase (day/night).
The response shows Gamma-distribution, but to make the model work I had to transform my response by adding 1, as the Gamma distribution can't handle non-positive data and quite a few of my data points were zeros as shown in this histogram:
Also, I had to scale the predictors, otherwise I got convergence warnings like
Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
I did this with scale(..., center = TRUE)
.
My model formula looks like this:
mod <- glmer(Species_Frequency ~ scaled_Minimal_Distance1 +
scaled_Minimal_Distance2 +
(scaled_Minimal_Distance3 * Dayphase),
data = data,
na.action = na.fail,
family = Gamma(link = "log"),
control = glmerControl(optimizer = "bobyqa"))
Now I want to plot the results of mod
using plot(allEffects(mod))
.
For plotting, I am backscaling my predictors in the allEffects
-object by accessing
allEffects(mod)[["scaled_Minimal_Distance1"]][["x"]][["scaled_Minimal_Distance1"]]
and doing as shown Here. I would also like to back-transform my response, to make the plot more understandable. Otherwise one would always have to keep in mind that 1 on the y-axis is actually 0, 2 is 1 etc. Can someone help me on how to do this, as I hit a roadblock and can't seem to figure it out myself.
Thank you very much in advance.
r plot
1
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35
add a comment |
I have fitted a few models using glmer
from thelme4
package and did model selection with MuMIn::dredge()
followed by model averaging. My response is frequency of occurrence of an animal in front of camera traps (continuous, number of photos per 100 hours of camera time); the predictors are minimum distances from a camera trap to landscape categories in meters, sometimes with an interaction with the day phase (day/night).
The response shows Gamma-distribution, but to make the model work I had to transform my response by adding 1, as the Gamma distribution can't handle non-positive data and quite a few of my data points were zeros as shown in this histogram:
Also, I had to scale the predictors, otherwise I got convergence warnings like
Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
I did this with scale(..., center = TRUE)
.
My model formula looks like this:
mod <- glmer(Species_Frequency ~ scaled_Minimal_Distance1 +
scaled_Minimal_Distance2 +
(scaled_Minimal_Distance3 * Dayphase),
data = data,
na.action = na.fail,
family = Gamma(link = "log"),
control = glmerControl(optimizer = "bobyqa"))
Now I want to plot the results of mod
using plot(allEffects(mod))
.
For plotting, I am backscaling my predictors in the allEffects
-object by accessing
allEffects(mod)[["scaled_Minimal_Distance1"]][["x"]][["scaled_Minimal_Distance1"]]
and doing as shown Here. I would also like to back-transform my response, to make the plot more understandable. Otherwise one would always have to keep in mind that 1 on the y-axis is actually 0, 2 is 1 etc. Can someone help me on how to do this, as I hit a roadblock and can't seem to figure it out myself.
Thank you very much in advance.
r plot
I have fitted a few models using glmer
from thelme4
package and did model selection with MuMIn::dredge()
followed by model averaging. My response is frequency of occurrence of an animal in front of camera traps (continuous, number of photos per 100 hours of camera time); the predictors are minimum distances from a camera trap to landscape categories in meters, sometimes with an interaction with the day phase (day/night).
The response shows Gamma-distribution, but to make the model work I had to transform my response by adding 1, as the Gamma distribution can't handle non-positive data and quite a few of my data points were zeros as shown in this histogram:
Also, I had to scale the predictors, otherwise I got convergence warnings like
Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
I did this with scale(..., center = TRUE)
.
My model formula looks like this:
mod <- glmer(Species_Frequency ~ scaled_Minimal_Distance1 +
scaled_Minimal_Distance2 +
(scaled_Minimal_Distance3 * Dayphase),
data = data,
na.action = na.fail,
family = Gamma(link = "log"),
control = glmerControl(optimizer = "bobyqa"))
Now I want to plot the results of mod
using plot(allEffects(mod))
.
For plotting, I am backscaling my predictors in the allEffects
-object by accessing
allEffects(mod)[["scaled_Minimal_Distance1"]][["x"]][["scaled_Minimal_Distance1"]]
and doing as shown Here. I would also like to back-transform my response, to make the plot more understandable. Otherwise one would always have to keep in mind that 1 on the y-axis is actually 0, 2 is 1 etc. Can someone help me on how to do this, as I hit a roadblock and can't seem to figure it out myself.
Thank you very much in advance.
r plot
r plot
edited Mar 8 at 20:43
Ben Bolker
135k13228320
135k13228320
asked Mar 7 at 20:31
MatthiasMatthias
63
63
1
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35
add a comment |
1
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35
1
1
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052338%2fbacktransforming-response-for-plotting-alleffects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052338%2fbacktransforming-response-for-plotting-alleffects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What do you mean by "frequency of occurrence"? You seem to say that the responses are 0,1,2,... which you transform to 1,2,3,... This seems more like number of occurrences (and counts are discrete while the Gamma distribution is continuous).
– dipetkov
Mar 7 at 20:57
What is the ratio of zero to non-zero? It might be worth looking at a Poisson or Negative Binomial distribution, they have ways of dealing with zeroes - en.wikipedia.org/wiki/Zero-inflated_model
– hrabel
Mar 7 at 21:16
Please see my edits. I have misformulated this, the "1 is 0 etc" thing described the values on the y-axis, my frequency is continuous. @hrabel I have added a histogram of my non-transformed data. I tried poisson, but as it is non-integer, it didn't work. I should maybe add, that I am quite unexperienced in statistics.
– Matthias
Mar 8 at 7:35