Linear Contrast

How to do a linear contrast with nonparametric regression

In R, we can use  sm.regression()  for apply non parametric regression. We add the option model=”linear”  to do a linear contrast.  The example showed here is about results of mba grade  with 3 variables: gender, gmat and gpa. The objetive is estimate gpa given gmat.

mba <- read.table('mbagrade.dat', header = T)
library(ggplot2)
ggplot(data=mba, aes(x=GMAT, y=GPA)) +
  geom_point(color='#8da0cb', size=3) +
  ggtitle('MBA') +
  theme(plot.title = element_text(face='bold', size=22)) +
  theme(axis.title = element_text(face='bold', size=12))

unnamed-chunk-2-1.png

library(sm)
smreg <- sm.regression(mba$GMAT,mba$GPA,h=40, model='linear')
df  <- data.frame(eval=smreg$eval.points, est=smreg$estimate, se=smreg$se, model.y=smreg$model.y)
df <- data.frame(df, lwr=df$model.y+2*df$se, upr=df$model.y-2*df$se)

ggplot() +
  geom_point(data=mba, aes(x=GMAT, y=GPA), color='#8da0cb', size=3) +
  geom_ribbon(data=df, aes(x=eval,  ymin=lwr, ymax=upr), fill='#fc8d62', alpha=0.2) +
  geom_line(data=df, aes(x=eval, y=est), col='#fc8d62', size=1.2) +
  ggtitle('MBA - Linear Test') +
  theme(plot.title = element_text(face='bold', size=22)) +
  theme(axis.title = element_text(face='bold', size=12))  

unnamed-chunk-4-1.png

We not reject linear hypothesis with p-value 0.469,  according to the smoothing parameter choosen.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s