[R] left.solve

Stephen R. Laniel laniel at stat.cmu.edu
Thu Oct 21 06:44:54 CEST 1999


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)
}






More information about the R-help mailing list