Question

Quadratic terms are quite common in regression. Here is an example from John Fox (http://www.jstatsoft.org/v08/i15/paper)

library(car) # For data
library(splines)  # For bs()
library(effects) # For plotting

data(Prestige)

prestige.mod <- lm(prestige ~ log(income) + bs(education, df=3) + poly(women, 2), data=Prestige)
summary(prestige.mod)

test <- plot(all.effects(prestige.mod, default.levels=50))

enter image description here

Is there any command in R to get the minimum/maximum of a quadratic effect right away without deriving in manually/plotting it?

Was it helpful?

Solution

If I understand correctly I would be approximating value of "women" at which the "minimum effect" were to be found:

idx <-  which.min( predict(prestige.mod, newdata= data.frame(
       women=seq(min(Prestige$women), max(Prestige$women), length=100), 
       income=mean(Prestige$income, na.rm=TRUE), 
       education=mean(Prestige$education, na.rm=TRUE) ) ) )
idx
#37 
#37 
# Just copy the argument to the newdata argument in predict call above
# and get the value that produced the minimum
 seq(min(Prestige$women), max(Prestige$women), length=100)[idx]
#[1] 35.45818

The use of the predict function on value sequences contained in "newdata" dataframes is undoubtedly happening "underneath the hood" for the plotting of those "effects".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top