Contrasting Effect

How to apply no effect test in R with nonparametric regression

For contrast no effect test we’ll use the dataset trawl from sm library, in R. The data refer to a survey of the fauna on the sea bed lying between the coast of northern Queensland and the Great Barrier Reef. The independent variable is Depth, the bottom depth of the zone 1 in 1993, and the predictor variable is Score1. 

Load data and apply nonparametric regression with sm library:

library(sm)
library(ggplot2)
attach(trawl)
ind <- c(Zone==1, Year==1, !is.na(Depth))
x <- Depth[ind]
y <- Score1[ind]
df.xy <- data.frame(x=x, y=y)
ggplot(data=df.xy, aes(x=x, y=y)) +
geom_point(color='#006699', size=3.5) +
ggtitle('Trawl Data') +
theme(plot.title = element_text(face='bold', size=32)) +
theme(axis.title = element_text(face='bold', size=22))

unnamed-chunk-1-1.png

smreg <- sm.regression(x,y, h = 5, model='no effect')
## Test of no.effect model: significance = 0.068
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=df.xy, aes(x=x, y=y), color='#006699', size=3.5) +
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='#ff1493', size=1.2) +
ggtitle('Trawl - No Effect Test') +
theme(plot.title = element_text(face='bold', size=32)) +
theme(axis.title = element_text(face='bold', size=22))

unnamed-chunk-3-1.png

st <- sig.trace(sm.regression(x,y,model='no.effect', display='none'), hvec=seq(5,20,length=10))
## Test of no.effect model: significance = 0.068
## Test of no.effect model: significance = 0.058
## Test of no.effect model: significance = 0.047
## Test of no.effect model: significance = 0.039
## Test of no.effect model: significance = 0.033
## Test of no.effect model: significance = 0.03
## Test of no.effect model: significance = 0.027
## Test of no.effect model: significance = 0.025
## Test of no.effect model: significance = 0.023
## Test of no.effect model: significance = 0.022
ggplot() +
geom_line(data=as.data.frame(st), aes(x=h, y=p), color='#006699', size=1.2) +
geom_hline(aes(yintercept = 0.05),color='#006699', lty=2, size=1, alpha=0.8) +
ggtitle('Significance Trace') +
theme(plot.title = element_text(face='bold', size=32)) +
theme(axis.title = element_text(face='bold', size=22))

unnamed-chunk-5-2Estimated regression is outside the reference bands asociated with null hypothesis, so for central observations the relation between Depth and Score1 is stronger than in limits values of Depth. Significance trace shows smooth parameter can change the result of the test. With h>8, we reject the null hypothesis with level of 0.05.

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