[R] pR2 stumped

ivo welch ivo.welch at anderson.ucla.edu
Tue May 7 03:29:39 CEST 2013


Dear R experts:  I am stumped.    I am trying to pick off the mcfadden
R^2 for a probit.  simple, me thinks---except my code works only in my
main program, but not in my sub!?    I am probably doing something
obviously wrong, but I have stared at my code for a while now and I
feel even more stupid than usually.  am I doing something obviously
wrong here?  advice, as always, appreciated.  /iaw


library(MASS)
library(pscl)

summarize <- function(p) {
  pp <- polr( factor(r1) ~ factor(r2), Hess=TRUE, data=p, method="probit" )
  print(pp)
  cat("---------------- (sub) now we do the pseudo R^2\n")
  print(pR2(pp))  ## it fails in the summarize sub program, wanting 'p'  huh?
  cat("---------------- ok\n")
}

################################################################
d <- data.frame(r1=factor( c("a", "a", "b", "b", "c", "c") ),
r2=factor( c("a", "b", "c", "b", "c", "a") ))
################################################################

### it works in the main program
pp <- (polr( factor(r1) ~ factor(r2), Hess=TRUE, data=d, method="probit" ))
print(pp)
cat("---------------- (main) now we do the pseudo R^2\n")
print(pR2(pp))
cat("---------------- ok\n")
summarize(d)

 Error in eval(expr, envir, enclos) : object 'p' not found.

----
Ivo Welch (ivo.welch at gmail.com)



More information about the R-help mailing list