Last data update: 2014.03.03

R: Tests linear versus partial linear model
partlintestR Documentation

Tests linear versus partial linear model

Description

Given a response y, a predictor x, and covariates z, the model y=m(x) +b'z +e is considered, where e is a mean-zero random error. There are three options for the null hypothesis: h0=0 tests m(x) is constant; h0=1 tests m(x) is linear, and h0=2 tests m(x) is quadratic. The (respective) alternatives are: m(x) is increasing or decreasing, m(x) is convex or concave, and m(x) is hyper-convex or hyper-concave (referring to the third derivative of m).

Usage

partlintest(x, y, zmat, h0 = 0, nsim = 1000)

Arguments

x

a vector of length n; this is the main predictor of interest

y

a vector of length n; this is the response

zmat

an n by k matrix of covariates, should be full column rank .

h0

An indicator of what null hypothesis is to be tested: h0=0 for the null hypothesis: m(x) is constant; h0=1 tests m(x) is linear, and h0=2 tests m(x) is quadratic.

nsim

The number of simulations used in creating the null distribution of the test statistic. The default is nsim=1000, if a more precise p-value is desired, make nsim larger.

Details

For the constant null hypothesis, the alternative fit is either the monotone increasing or monotone decreasing fit – whichever minimizes the sum of squared residuals. For the linear null hypothsis, the alternative fit is either convex or concave, and for the quadratic null hypothesis, the alternative fit is constrained so that the third derivative is either positive or negative over the range of x-values.

Value

pval

The p-value for the test

p0

The null hypothesis fit

p1

The "positive" fit

p2

The "negative" fit

Author(s)

Mary C Meyer and Bodhisattva Sen

References

TBA

See Also

agconst,doubconetest

Examples

data(derby)
n=length(derby$speed)
zmat=matrix(0,nrow=n,ncol=2);zvec=1:n*0+1
zmat[derby$cond=="good",1]=1;zvec[derby$cond=="good"]=2
zmat[derby$cond=="fast",2]=1;zvec[derby$cond=="fast"]=3
ans=partlintest(derby$year,derby$speed,zmat,h0=2)
ans$pval
par(mar=c(4,4,1,1));par(mfrow=c(1,2))
plot(derby$year,derby$speed,col=zvec,pch=zvec)
points(derby$year,ans$p0,pch=20,col=zvec)
title("Null fit")
legend(1980,51.6,pch=3:1,col=3:1,legend=c("fast","good","slow"))
plot(derby$year,derby$speed,col=zvec,pch=zvec)
points(derby$year,ans$p1,pch=20,col=zvec)
title("Alternative fit")

data(adhd)
n=length(adhd$sex)
zmat=matrix(0,nrow=n,ncol=2)
zmat[adhd$sex==1,1]=1
zmat[adhd$ethn<5,2]=1
ans=partlintest(adhd$hypb,adhd$fcn,zmat,h0=1)
ans$pval
cols=c("pink3","lightskyblue3")
plot(adhd$hypb,adhd$fcn,col=cols[zmat[,1]+1],pch=zmat[,2]+1,
xlab="Hyperactive behavior level",ylab="Social and Academic Function Score")
cols2=c(2,4)
points(adhd$hypb,ans$p1,col=cols2[zmat[,1]+1],pch=20)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DoubleCone)
Loading required package: coneproj
Loading required package: Matrix
Loading required package: MASS
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DoubleCone/partlintest.Rd_%03d_medium.png", width=480, height=480)
> ### Name: partlintest
> ### Title: Tests linear versus partial linear model
> ### Aliases: partlintest
> ### Keywords: partial linear test semiparametric
> 
> ### ** Examples
> 
> data(derby)
> n=length(derby$speed)
> zmat=matrix(0,nrow=n,ncol=2);zvec=1:n*0+1
> zmat[derby$cond=="good",1]=1;zvec[derby$cond=="good"]=2
> zmat[derby$cond=="fast",2]=1;zvec[derby$cond=="fast"]=3
> ans=partlintest(derby$year,derby$speed,zmat,h0=2)
> ans$pval
[1] 0.46
> par(mar=c(4,4,1,1));par(mfrow=c(1,2))
> plot(derby$year,derby$speed,col=zvec,pch=zvec)
> points(derby$year,ans$p0,pch=20,col=zvec)
> title("Null fit")
> legend(1980,51.6,pch=3:1,col=3:1,legend=c("fast","good","slow"))
> plot(derby$year,derby$speed,col=zvec,pch=zvec)
> points(derby$year,ans$p1,pch=20,col=zvec)
> title("Alternative fit")
> 
> data(adhd)
> n=length(adhd$sex)
> zmat=matrix(0,nrow=n,ncol=2)
> zmat[adhd$sex==1,1]=1
> zmat[adhd$ethn<5,2]=1
> ans=partlintest(adhd$hypb,adhd$fcn,zmat,h0=1)
> ans$pval
[1] 0.038
> cols=c("pink3","lightskyblue3")
> plot(adhd$hypb,adhd$fcn,col=cols[zmat[,1]+1],pch=zmat[,2]+1,
+ xlab="Hyperactive behavior level",ylab="Social and Academic Function Score")
> cols2=c(2,4)
> points(adhd$hypb,ans$p1,col=cols2[zmat[,1]+1],pch=20)
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>