Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Last active January 3, 2016 12:39
Show Gist options
  • Save erikpukinskis/8464140 to your computer and use it in GitHub Desktop.
Save erikpukinskis/8464140 to your computer and use it in GitHub Desktop.
# These are the coefficients that R gives me from my logistic regression:
intercept = 0.2700309
coefficients = {
high: 1.0136028,
low: 1.0016712,
germ_mean: 1.0233327,
gdds: 0.9990283,
early_gdds: 0.9986464,
mid_gdds: 1.0002979,
late_gdds: 0
}
# And this is what R predicts for one datum:
#
# outcome high low germ_mean gdds early_gdds mid_gdds late_gdds p_success
# 1 1 73 28 40 119 0 91 28 0.5578460
# ...
# So to get my own p_success, first I multiply each coefficient by it's input data
period = {:high=>73, :low=>28, :germ_mean=>40, :gdds=>119, :early_gdds=>0, :mid_gdds=>91, :late_gdds=>28}
products = coefficients.map {|name,value| period[name]*value }
# Then I add those together and add that to the intercept
predicted_logit = intercept + products.sum
# Then my probability should be e^predicted_logit over 1 + e^predicted_logit:
odds_ratio = Math.exp(predicted_logit) / (1 + Math.exp(predicted_logit))
# But the odds ratio comes out as 1.0, not 0.5578460 like R predicts.
@mcke
Copy link

mcke commented Jan 17, 2014

Erik - just saw this on FB. What command did you use in R? Is it possible those are the odds ratios rather than the coefficients? I'm thinking they might be since none are negative.

Good luck!

-Matt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment