R/rhom.R

rhom <-
function(x,y,op=1,op2=FALSE,tr=.2,plotit=TRUE,xlab="NA",ylab="NA",zlab="ABS(res)",
est=median,sm=FALSE,SEED=TRUE,xout=FALSE,outfun=outpro,...){
# For regression model, Y=m(X)+s(X)e,
# where s(X) models heteroscedasticity, and e has median 0,
# test hypothesis s(X)=1 for any X
#
# For p>1, method tests for each p whether residuals and x_j
# have a horizontal regression line.
#
# op2=F, tests for homogeneity using running interval smoother
# op2=T, test of independence based on Y-M(Y), M(Y) some measure
#        of location given by argument est.
#  In general, op2=T should NOT be used when the goal is to test
#  the hypothesis of a homoscedastic error term.
#
# op=1 test using regression method (function regci)
# op=2 test using Winsorized correlation
#      tr is amount of Winsorizing. A heteroscedastic bootstrap method is used. wincor is not asymptotically correct.
# op=3 test using a wild boostrap method
#
x<-as.matrix(x)
p<-ncol(x)
pp<-p+1
xy<-elimna(cbind(x,y))
x<-xy[,1:p]
y<-xy[,pp]
x<-as.matrix(x)
if(xout){
m<-cbind(x,y)
flag<-outfun(x,plotit=FALSE,...)$keep
m<-m[flag,]
x<-m[,1:p]
y<-m[,pp]
x<-as.matrix(x)
}
output<-NA
if(ncol(x)==1){
if(!op2)res<-y-runhat(x,y,est=est,pts=x)
if(op2)res<-y-est(y)
if(op==1)output<-regci(x,abs(res),SEED=SEED,pr=FALSE)$regci[2,5]
if(op==2)output<-wincorci(x,abs(res),tr=tr,SEED=SEED)$p.value
if(op==3)output<-indt(x,abs(res),SEED=SEED)$p.value.d
}
if(ncol(x)>1){
pv<-ncol(x)+1
if(!op2)res<-y-rung3hat(x,y,est=est,pts=x)$rmd
if(op2)res<-y-est(y)
if(op==1)output<-regci(x,abs(res),pr=FALSE)$regci[2:pv,5]
if(op==2)output<-winall(cbind(x,abs(res)),tr=tr)$p.values[1:ncol(x),pv]
if(op==3)output<-indt(x,abs(res),SEED=SEED)$p.value.d
}
if(plotit){
if(ncol(x)==1){
if(xlab=='NA')xlab="X"
if(ylab=='NA')ylab="ABS(res)"
if(!sm)rungen(x,abs(res),est=est,xlab=xlab,ylab=ylab)
if(sm)runmbo(x,abs(res),est=est,xlab=xlab,ylab=ylab)
}
if(ncol(x)==2){
if(xlab=='NA')xlab="X1"
if(ylab=='NA')ylab="X2"
if(sm)rung3d(x,abs(res),est=est,xlab=xlab,ylab=ylab,zlab=zlab)
if(!sm)run3bo(x,abs(res),est=est,xlab=xlab,ylab=ylab,zlab=zlab)
}}
list(p.value=output)
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.