Solved – How to calculate Odds Ratio with R

autocorrelationodds-ratior

I have a dataset that looks like this:

> scores
         date scores price
1  30/11/2017      1     1
2  01/12/2017      1     0
3  02/12/2017      0     1
4  03/12/2017      1     0
5  04/12/2017      1     1
6  05/12/2017      1     0
7  06/12/2017      1     0
8  07/12/2017      1     1

I would like to calculate the odds ratio but I can't seem to find a way.
Is there an easy way to do it?

Thanks in advance

UPDATE

I've used the questionr package and the odds.ratio function and I've obtained this:

> odds.ratio(table(scores$scores, scores$price))
                   OR   2.5 % 97.5 %      p
Fisher's test 2.18493 0.58581 8.4658 0.2374

can you please help me interpret the results? I'm relatively new to this.

EDIT

Basically I'm doing a project for my university. I have binarized sentiment scores for each day (0 if they are under a mean score and 1 if above) and binarized stock price variations (0 if price is lower than previous day, 1 if above). My teacher suggested to run odds ratio to see if sentiment by investor could influence the price variations, so I did it, but I dont know how to interpret them since all I can find about odds ratio are examples with presence/absence of a desease. My guess was that when the sentiment is positive (value of 1, and I will consider this class as the "exposure" class of the medical examples) the stock price has a possibility to increase (value of 1, considered as the "oucome" class) that is 2.1 times bigger than it would be with a negative sentiment (value of 0). But I'm absolutely NOT sold on this interpretation

Best Answer

Without more context for the meaning of your variables, it is hard to help you interpret your results. You want to do an odds ratio, but why? Normally, though, you can interpret the odds ratio as an effect size between two groups. In your case, things with price=1 had sales=1 2.1 times as much. Note, however, the large range of vales around your estimate and that it is not statistically significant. Finally, as noted by another user, neglecting to control fir autocorrelation will increase your chances of a type-1 error. I recommend a hierarchical linear model for longitudinal data and test for AR(1) in the level-1 error. If you have more data points, you might be able to use an autoregressive latent trajectory.