1
$\begingroup$

I'm working on the Titanic data and I plotted local regression curves for a couple predictors.

library('vcdExtra')
data(Titanicp)

ggplot(Titanicp, aes(age, as.numeric(survived)-1, color=sex)) +
  stat_smooth(method="loess", formula=y~x,
              alpha=0.2, size=2, aes(fill=sex)) + facet_grid(~pclass) 

enter image description here

I thought the y-axis was probability, but it exceeds 1. What is it?

$\endgroup$
2
  • $\begingroup$ Your code is not reproducible - there is no object imp.train defined with that code. $\endgroup$
    – Ben
    Jan 22, 2019 at 1:01
  • $\begingroup$ Let's underline that once you've specified age, class, sex you're often not playing with much data for each smoothed value, regardless of neighbouring values providing support. So uncertainty about the smooths should be no surprise, and as @peteR flags, the routine doesn't know about the bounds on the response. $\endgroup$
    – Nick Cox
    Jan 22, 2019 at 9:01

2 Answers 2

1
$\begingroup$

R (ggplot) does not know that it is a probability and the loess curve might therefore leave the range [0,1].

$\endgroup$
1
$\begingroup$

The plot gives you the answer - it is the variable as.numeric(Survived) - 1. So, whatever your Survived variable is, this is converting it to a number, then subtracting one. The result of that operation is what is plotted on the vertical axis. Since you have used a loess fit, the curves are showing a smoothed estimate of this variable.

$\endgroup$
1
  • $\begingroup$ That's the question. Survived is a 1/0 factor variable, so it showing the percent who survived by age and gender. Which poses the question, how do you get > 100% survival? $\endgroup$
    – Sebastian
    Jan 22, 2019 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.