R/logrsm.R

logrsm <-
function(x,y,fr=1,plotit=TRUE,pyhat=FALSE,xlab="X",ylab="Y",STAND=TRUE,
xout=FALSE,outfun=outpro,LP=TRUE,...){
#
#  Do a smooth as described by Hosmer and Lemeshow, p. 85
#
#  Assuming there is only one predictor
#
# xout=T will remove outliers from among the x values and then fit
# the regression line.
#  Default: a mad-median rule is used.
#
# LP=TRUE smooth the initial smooth using LOESS
#
x<-as.matrix(x)
if(ncol(x)>1)stop("With more than one predictor, use logSM")
xy=elimna(cbind(x,y))
x=xy[,1:ncol(x)]
y=xy[,ncol(xy)]
x<-as.vector(x)
if(xout){
flag<-outfun(x,...)$keep
x<-x[flag]
y<-y[flag]
}
if(STAND)x<-(x-median(x))/mad(x)
m1<-outer(x,x,"-")^2
m2<-exp(-1*m1)*(sqrt(m1)<=fr)
m3<-matrix(y,length(y),length(y))*m2
yhat<-apply(m3,2,sum)/apply(m2,2,sum) #sum over rows for each column
if(plotit){
xor<-order(x)
plot(x,y,xlab=xlab,ylab=ylab)
if(!LP)lines(x[xor],yhat[xor])
if(LP){
Yhat=lplot(x[xor],yhat[xor],pyhat=TRUE,plotit=FALSE)$yhat.values
lines(x[xor],Yhat)
}
}
output<-"Done"
if(pyhat)output<-yhat
list(output=output)
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.