3
$\begingroup$

I'm using R and have a dataset which contains data for a certain experiment which is tested multiple times in environments with different P values. The success or failure of the experiment is denoted by 1 or 0 respectively. An example below.

success   P
   1       15639
   1       18623
   1       19875
   0       12513
   0       10256
   1       12548
   1       15789
   0       12568
   0       10236
   1       15478
   0       11256
   1       12546
   0       10256
   1       14562
   0       10258
   0       11254
   1       12458
   1       13458
   0       12001
   1       14756
   0       10112
   0       11256
   1       13485
   1       12369
   0       11297
   1       12100
   1       15780
   0       11300
   0       10300
   1       12596

I now want to calculate and preferably also plot at which P value the experiment has a 50% chance of succeeding. What type of statistical measurement/plot should be used for this scenario?

$\endgroup$
5
  • $\begingroup$ Have you tried logistic regression? If you add more data, I can show you how to do this in R. $\endgroup$ Commented Dec 16, 2019 at 17:48
  • $\begingroup$ I've not tried this yet but I'll definetly look it up now! I've expanded the dataset to around 30 examples, would that be enough or how many samples would you require? $\endgroup$
    – Astarno
    Commented Dec 16, 2019 at 19:06
  • $\begingroup$ You wrote Ph. Do you mean phosphorus, pH or something else? If pH, then the values are surprising. $\endgroup$
    – Nick Cox
    Commented Dec 16, 2019 at 21:08
  • $\begingroup$ May you clarify please what P column in example you have presented does means. If it is p-values then why them are not between 0 and 1? $\endgroup$
    – Bogdan
    Commented Dec 17, 2019 at 12:39
  • $\begingroup$ @Bogdan I edited Ph to P because I believed that it might be phosphorus but was unlikely to be pH. It's not intended to be P-value, i.e. observed significance level. $\endgroup$
    – Nick Cox
    Commented Dec 17, 2019 at 16:24

1 Answer 1

2
$\begingroup$

How To Find the 50% Point

I am assuming you have your data in a dataframe or tibble named data.

The easiest way to find a point estimate for the ph value which elicits 50% success rate is to perform a logistic regression. I won't go into the details of the model here, but you can easily read up on it.

With R...

#Rescale your data because the values are large
data = data %>% mutate(ph = PhValue/1000)

#Perform the regression
model = glm(success ~ ph, family = binomial(), data = data)

point_50p = -coef(model)['(Intercept)']/coef(model)['ph']

From the sample provided, it looks like the 50% point is approx 12,228.5.

Why Does This Work

Logistic regression models the log odds of the outcome as so

$$\log \left( \dfrac{p}{1-p} \right) = \beta_0 + \beta_1x$$

A log odds of 0 corresponds to a probability of 50%, so simply solve

$$ \beta_0 + \beta_1x = 0$$

Some simple algebra yields the solution.

$$ x = \dfrac{-\beta_0}{\beta_1} $$

Can We Do Better?

I would think so. The problem with this solution is that we only get a point estimate. What would be better is a confidence interval, but that presently eludes me.

Moving On; The Plot

Here is how we can plot this with R...

data %>% #Your data
  ggplot(aes(ph,success))+
  geom_jitter(height = 0.05, width = 0, alpha = 0.5)+
  geom_smooth(method = 'glm', method.args = list(family='binomial'))+
  geom_segment(aes(y = 0.5, yend = 0.5, x = 10, xend = point_50p))+
  geom_segment(aes(y = 0.5, yend = 0, x = point_50p, xend = point_50p))

Yielding

enter image description here

I like geom jitter because it allows me to see the density of points along the x axis, rather than obfuscating them.

$\endgroup$

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.