title: Plot the results of a multivariate logistic regression model in R
body: <p>I would like to plot the results of a multivariate logistic regression analysis (GLM) for a specific independent variables adjusted (i.e. independent of the confounders included in the model) relationship with the outcome (binary).</p>
  
  <p>I have seen posts that recommend the following method using the <code>predict</code> command followed by <code>curve</code>, here's an example;</p>
  
  <pre><code>x     &lt;- data.frame(binary.outcome, cont.exposure)
  model &lt;- glm(binary.outcome ~ cont.exposure, family=binomial, data=x)
  plot(cont.exposure, binary.outcome, xlab="Temperature",ylab="Probability of Response") 
  curve(predict(model, data.frame(cont.exposure=x), type="resp"), add=TRUE, col="red")
  </code></pre>
  
  <p>However this does not seem to work for multivariate regression models. I get the following error when I add 'age' (arbitrary - could be any variable of same length) as a confounding variable;</p>
  
  <pre><code>&gt; x     &lt;- data.frame(binary.outcome, cont.exposure, age)
  &gt; model &lt;- glm(binary.outcome ~ cont.exposure + age, family=binomial, data=x)
  &gt; plot(cont.exposure, binary.outcome, xlab="Temperature",ylab="Probability of Response") 
  &gt; curve(predict(model, data.frame(cont.exposure=x), type="resp"), add=TRUE, col="red")
  Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
    variable lengths differ (found for 'age')
  In addition: Warning message:
    'newdata' had 101 rows but variable(s) found have 698 rows 
  </code></pre>
  
  <hr>
  
  <p>The above model is a simplified version of the models I'd like to run, but the principle is the same; <strong>I would like to plot the relationship between a binary outcome variable and a continuous exposure, independent of confounding factors.</strong>.</p>
  
  <p>It would be great to get either a workaround for the above, or an alternative way to view the relationship I am interested in. Many thanks.</p>