# Weighting observations in binary logistic regression

I am working in program R. I am modeling the incidence of flight in a seabird in relation to distance to the nearest ship (potential disturbance, range = 0 to 74 km from the bird). 1= flight during observation, 0 = no flight. The bird does fly with some unknown probability when no ships are present or really "far" away. I am trying to find this really far distance and associated probability of flight using binary logistic regression.

Model = Flight ~ ship distance. Other variables were explored but fell out with stepwise selection.

During exploratory analysis I truncated the data down only looking at smaller distances from the ship (20, 15, 10 km). These models are highly significant and predict that as the ship gets closer the probability of flight increases. However when I include all the data (out to 74 km) the intercept is significant (and predicts the true % of observed flight events) but the slope term is non-significant.

Can I use a weighting scheme to give more weight to observations when the ship was closer?

Thanks.

Edit: I am working through the suggestions made by @Scortchi and @Underminer. Here is a plot of a loess smooth on the observed data to better help visualize the pattern. The distance to the ship data does not discriminate between approaching ships and departing ships it is just a straight line measure to the nearest ship. The dip in the probability of flight at 8.5 I believe can be attributed to "unaffected" birds that did not fly as the ship passed by them. So as the ship departs and gets further from the observation site we were more like to be observing birds that for whatever reason did not fly when the ship passed and are less likely to fly for "naturally occurring" reason. As additional birds fill back into the observation area the "baseline" flushing rate is resumed and birds start to fly at "normal" probabilities.

• Represent distance with a polynomial or restricted cubic spline rather than with a single linear term. – Scortchi - Reinstate Monica Jan 30 '14 at 20:50
• Also perhaps search for "stepwise" here, or read this paper & consider whether you're sure it's really solving a problem you have. – Scortchi - Reinstate Monica Jan 30 '14 at 23:27
• Thanks for posting the data plot, it certainly helps to visualize the data. As far as the Loess plot, I think it may be overfitting the data. Trying to explain to a scientist why a bird is approximately twice more likely to fly when a boat is 60km away than when the boat is 8km away would be difficult. Perhaps you could try increasing the smoothing parameter. – Underminer Jan 31 '14 at 18:04
• Could choose the smoothing bandwidth using cross-validation. What's interesting is determining whether the dip's real - an artefact of the experimental protocol or an interesting fact about bird behaviour - or just overfitting, as @Underminer suggests it might be. – Scortchi - Reinstate Monica Jan 31 '14 at 19:39
• I agree with @Scortchi; choosing the smoothing bandwidth with cross-validation sounds like a good idea. – Underminer Jan 31 '14 at 19:42

Weighting observations differently is appropriate when some measurements are made with greater precision than others.

In this case the problem is much more likely with the functional form of your model: assuming a linear relationship between the logit of flight probability & ship distance. Use a model that's suggested by theory, or one that's flexible enough to incorporate curvature: polynomials & restricted cubic splines are the standard choices; mine would probably be splines for the situation you described

Based on what you have told me of the study, I believe it would be perfectly acceptable to model close ship distances (truncate the data as you have done) separately from far ships if it appears the ships have no effect on the birds if they are too far away. You could do what is called broken-stick regression, also known as segmented or piecewise regression.

I would suggest plotting the response by distance, and if there appears to be a distinct difference in the model when ship distance is high compared to when the ship distance is low, this provides good evidence using broken-stick regression. I have a hunch (without seeing your data) that birds are not affected by far away ships at all (because they cannot even sense the ships), but may nicely fit the logistic regression as ships get closer. This would explain why the logistic regression coefficient was insignificant when all distances were included, yet it was significant when fit on the truncated data (see example scenario below). If the data support this idea, you could find the breakpoint and then fit both sides separately.

The diagram below is a simple example of what I think your data may look like. The solid dots represent the data (Fly/notFly vs Distance). I then noticed that it appears the close Distances are more likely to result in Fly, but high Distances seem to have a constant (and low) probability of Fly as if they are unaffected by Distance. So I modeled the Distances <40 using logistic (blue predicted probabilities), and considered anything after 40 to be a flat line at the last predicted probability (red predicted probabilities). This makes the inherent assumption that after a certain point, distance does not matter at all (seems reasonable enough to me). Logistic regression performed on all distances gave the following fit (notice Distance is not significant): Logistic regression performed on Distance<40 gave the following fit (notice Distance is significant now): Even if you do down weight the far distance observations, you would in effect be stating that you believe the far away cases are less important (because they don't fit the model), so you might as well model them separately.

Here is the R code I used to generate the example if you are interested:

# Generate made up data
Fly = c(1,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1)
Distance = c(1:20, 20+2*(1:10), 40+4*(1:10))
plot(Fly ~ Distance)

# Fit all distances using logistic regression
fitAll = glm(Fly ~ Distance, family = binomial)
summary(fitAll)

# Fit 30 closest points (Distance <40) only
fitClose = glm(Fly[1:30] ~ Distance[1:30], family = binomial)
summary(fitClose)

# Plot logistic regression predicted probabilities for Distance <40
points(fitClose$fitted ~ Distance[1:30], col = "blue") # Plot second regression probabilities for Distance >40 points(rep(fitClose$fitted,10) ~ Distance[31:40], col = "red")

• As a side note, the fit seemed fairly robust to the choice of the breakpoint used. – Underminer Jan 30 '14 at 21:13
• (+1) I'd rather have a model with no discontinuities & not have to choose the breakpoint in any data-dependent way, but you've explained the issues well & that's a sensible approach. – Scortchi - Reinstate Monica Jan 30 '14 at 21:22
• @Scortchi, I agree choosing the breakpoint could potentially be a problem. Perhaps estimating/justifying it via cross-validation would be more acceptable. – Underminer Jan 30 '14 at 21:36
• I will take a look at a polynomial term, cubic splines and the broken stick method and report back. Thanks. – marcellt Jan 30 '14 at 21:59
• @marcellt: Good introduction to regression splines here. And some discussion of smoothing with loess, which I forgot to mention, & which is also useful for exploration. – Scortchi - Reinstate Monica Jan 30 '14 at 23:14