I have sort of an emergency question for the list. One of my professors
for an S-Plus intensive class distributed a function to produce partial
regression plots. I need to run it under R, because I'm doing the
homework on my home computer with a modem; hence I don't have the speed
required to emulate X-Windows and run S Plus off one of the campus
servers. Bottom line: I'm using R.
So I tried to run the professor's partreg.q file (attached to this
message), and received this message:
Error: couldn't find function "left.solve"
The offending code is in line 62:
Q_left.solve(R, cbind(rep(1,length(x)),x))
Second bottom line (if such a thing is possible): how do I make this code
work under R? Is the cause hopeless?
Thanks very much for any help anyone can provide.
--Steve
Stephen R. Laniel | "I've got a match:
Carnegie Mellon University | Your embrace and my collapse."
laniel at stat.cmu.edu | --They Might Be Giants
-------------- next part --------------
# Partial regression (added variable) plot
# H. Seltman 9/30/99
# Creates a partial regression plot
# Reference: Hamilton, Regression with Graphics, 1992, pp. 69, 125, 142
# Argument xlst= is a character vector of names of variables included
# in the regression OR a numeric or logical index vector identifying
# variables in "df" (y variable is removed if included)
# Argument yname= is the quoted name of the y variable
# Argument outname= is the covariate whose added effect is to be plotted
# Argument df= is the data.frame containing the x and y variables
# Argument main= is a title; default is a model formula
# Argument tcex= is the character size of the title
# Argument cex= is the character size of the x and y axis labels
# Argument id=T is for identification mode: left click on points
# to have them identified, middle click when done.
# Argument proportional=T plots points as circles proportional to DFBETAS
# Argument relsize changes proportional circles relative size
# Argument res=T plots residuals instead
# Argument f=2/3, e.g. sets neighbor fraction for lowess line
partreg_function(xlst, yname, outname, df, proportional=F, relsize=1,
main=NULL, tcex=1, cex=1, id=F, ares=F, f=NULL) {
jnk_par("fig")
relsize_relsize*(jnk[2]-jnk[1])*(jnk[4]-jnk[3])
if (!is.character(xlst))
xlst_names(df)[xlst]
if (!is.character(yname) || !is.character(outname))
stop("yname and outname must be in quotes")
if (length(xlst[xlst==yname])==1)
xlst_xlst[xlst!=yname]
if (length(xlst[xlst==outname])!=1)
stop(paste(outname,"is not in",paste(xlst, collapse=", ")))
if (is.null(main)) {
nam_xlst
nam[nam==outname]_paste("(",outname,")",sep="")
main_paste(yname,"~",sep="",paste(nam,collapse="+",sep=""))
}
xlst_xlst[xlst!=outname]
xform_paste(xlst,collapse="+",sep="")
if (xform=="") xform_"1"
x_lm(formula(paste(outname,"~",xform)),df,na.action=na.omit)$res
y_lm(formula(paste(yname,"~",xform)),df,na.action=na.omit)$res
rslt_lm(y~x,na.action=na.omit)
xlab_paste(outname, "on others residual")
ylab_paste(yname, "on all but", outname, "residual")
if (!proportional) {
if (ares) {
plot(rslt$fit, rslt$res)
abline(h=0,lty=2)
if (!is.null(f)) lines(lowess(rslt$fit,rslt$res, f=f))
} else {
plot(x, y, xlab=xlab, ylab=ylab, cex=cex)
if (!is.null(f)) lines(lowess(x,y,f=f))
}
} else {
lms_summary(rslt)
e_rslt$residuals
n_length(e)
beta_rslt$coef
p_length(rslt$coef)
R_rslt$R
Q_left.solve(R, cbind(rep(1,length(x)),x))
h_as.vector((Q^2 %*% array(1, c(p, 1))))
h.res_(1 - h)
z_e/h.res
v1_e^2
z_t(Q * z)
v.res_sum(v1)
v1_(v.res - v1/h.res)/(n-p-1)
dbeta_backsolve(R, z)
si_sqrt(v1)
xxi_diag(lms$cov.unscaled)
bi_t(beta-dbeta)
dfbetas_(t(coef(rslt)-t(bi)))/(si %o% xxi^.5)
adfbetas_abs(dfbetas[,2])
p1_(99/18)*adfbetas*(adfbetas+1)^2+1
p1[adfbetas>2]_100
symbols(x, y, circles=sqrt(p1), inches=0.2*relsize,
xlab=xlab, ylab=ylab, cex=cex)
}
title(main, cex=tcex)
if (!ares) abline(rslt)
if (id) identify(x, y, dimnames(df)[[1]])
rtn_list(x=x,y=y,rslt=rslt)
if (proportional) rtn_list(x=x,y=y,rslt=rslt,dfbetas=dfbetas)
invisible(rtn)
}
left.solve
2 messages · Stephen R. Laniel, Martin Maechler
"SRL" == Stephen R Laniel <laniel at stat.cmu.edu> writes:
SRL> I have sort of an emergency question for the list. One of my
SRL> professors for an S-Plus intensive class distributed a function to
SRL> produce partial regression plots. I need to run it under R,
SRL> because I'm doing the homework on my home computer with a modem;
SRL> hence I don't have the speed required to emulate X-Windows and run
SRL> S Plus off one of the campus servers. Bottom line: I'm using R.
SRL> So I tried to run the professor's partreg.q file (attached to this
SRL> message), and received this message:
SRL> Error: couldn't find function "left.solve"
SRL> The offending code is in line 62:
SRL> Q_left.solve(R, cbind(rep(1,length(x)),x))
SRL> Second bottom line (if such a thing is possible): how do I make
SRL> this code work under R? Is the cause hopeless?
Not at all :
Splus help on left.solve says
USAGE:
left.solve(r, x)
This is support for the functions lm.hat() and
lm.influence(). It is not intended to be called directly
by users.
I.e. your professor shouldn't have used it (;-) Then in S-plus (3.4)
dump("left.solve","")
"left.solve"<-
function(r, x)
{
# this should really be done using DTRSL in Linpack
x[] <- x %*% solve(r)
x
}
{you could have done this over the modem line (without X11..)}
If you add the above function definition to your *.q file (or a better place)
all should work.
And yes, I don't think we'd want this function in R...
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._