Skip to content

bug in polychor with R 2.6.0

8 messages · John Fox, Jan de Leeuw, Rob Goedman +2 more

#
John,
    I have been testing out R2.6.0 alpha to see if my psych package 
works.   I am running the R Gui for the Mac.

There seems to be a problem with the polychor function in your 
polycor package.  I think this might be a general problem with R 
2.6.0 alpha  but I am not sure.  I am copying the R mac list to see 
if this is a general problem with the alpha gui.

Bill


 From a clean start

[Workspace restored from /Volumes/WR/bill/.RData]
_
platform       i386-apple-darwin8.10.1
arch           i386
os             darwin8.10.1
system         i386, darwin8.10.1
status         alpha
major          2
minor          6.0
year           2007
month          09
day            14
svn rev        42851
language       R
version.string R version 2.6.0 alpha (2007-09-14 r42851)
Loading required package: mvtnorm
[1] 0.5285446
*** caught bus error ***
address 0x0, cause 'non-existent physical address'

Traceback:
  1: .Fortran("mvtdst", N = as.integer(n), NU = as.integer(df), LOWER 
= as.double(lower),     UPPER = as.double(upper), INFIN = 
as.integer(infin), CORREL = as.double(corrF),     DELTA = 
as.double(delta), MAXPTS = as.integer(maxpts), ABSEPS = 
as.double(abseps),     RELEPS = as.double(releps), error = 
as.double(error), value = as.double(value),     inform = 
as.integer(inform), PACKAGE = "mvtnorm")
  2: mvt(lower = lower, upper = upper, df = 0, corr = corr, delta = 
mean,     maxpts = maxpts, abseps = abseps, releps = releps)
  3: pmvnorm(lower = c(row.cuts[i], col.cuts[j]), upper = c(row.cuts[i 
+     1], col.cuts[j + 1]), corr = R)
  4: binBvn(rho, row.cuts, col.cuts)
  5: f(arg, ...)
  6: function (arg) f(arg, ...)(-0.23606797749979)
  7: optimise(f, interval = c(-1, 1))
  8: polychor(x, y)



Bill
#
Dear Bill,

This works fine for me under Windows XP with R 2.6.0 alpha, so I suspect a
problem with the Mac build:
plychr> set.seed(12345)

plychr> data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2))

plychr> x <- data[,1]

plychr> y <- data[,2]

plychr> cor(x, y)  # sample correlation
[1] 0.5285446

plychr> x <- cut(x, c(-Inf, .75, Inf))

plychr> y <- cut(y, c(-Inf, -1, .5, 1.5, Inf))

plychr> polychor(x, y)  # 2-step estimate
[1] 0.5365251

plychr> polychor(x, y, ML=TRUE, std.err=TRUE)  # ML estimate

Polychoric Correlation, ML est. = 0.5364 (0.03775)
Test of bivariate normality: Chisquare = 0.545, df = 2, p = 0.7615

  Row Threshold
  Threshold Std.Err.
     0.7292  0.04368


  Column Thresholds
  Threshold Std.Err.
1   -0.9947  0.04767
2    0.5100  0.04145
3    1.5450  0.06265


Regards,
 John

--------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------
1 day later
#
Bill,

Using R-2.6.0 alpha, the binary version of the package (for 2.6.0) of  
polycor seems to work fine. See below.

Don't think the version of the R GUI makes a difference here.

Regards,
Rob


R version 2.6.0 alpha (2007-09-06 r42791)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

...

trying URL 'http://cran.cnr.Berkeley.edu/bin/macosx/universal/contrib/ 
2.6/polycor_0.7-3.tgz'
Content type 'application/x-gzip' length 16643 bytes (16 Kb)
opened URL
==================================================
downloaded 16 Kb


The downloaded packages are in
	/tmp/Rtmp87kMzX/downloaded_packages

 > library(polycor)
Loading required package: mvtnorm
 > data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2))
 > x <- data[,1]
 >  y <- data[,2]
 >  cor(x, y)  # sample correlation
[1] 0.5285446
 > x <- cut(x, c(-Inf, .75, Inf))
 >  y <- cut(y, c(-Inf, -1, .5, 1.5, Inf))
 >  polychor(x, y)  # 2-step estimate
[1] 0.5365251
 > polychor(x, y, ML=TRUE, std.err=TRUE)

Polychoric Correlation, ML est. = 0.5364 (0.03775)
Test of bivariate normality: Chisquare = 0.545, df = 2, p = 0.7615

   Row Threshold
   Threshold Std.Err.
      0.7292  0.04368


   Column Thresholds
   Threshold Std.Err.
1   -0.9947  0.04767
2    0.5100  0.04145
3    1.5450  0.06265
 >
On Sep 15, 2007, at 10:49 AM, William Revelle wrote:

            
#
Has anyone noticed that the problem (whatever it is)
seems to occur in code from the included mvtnorm
package (specifically the guts of the
mvt() function), *not* the polycor package?
[cc'd to mvtnorm package maintainer]
#
Jan and Kasper,


I am running Mac OS X 10.4.10

R  framework  installed directly from  CRAN (ucla mirror) (i.e., I 
did not compile it, I just installed the framework and GUI).

polycor reinstalled from CRAN   (version 0.7.3)
also similar failure when using Rgraphviz  1.15.9
Rgraphviz installed from bioconductor using the  commands

source("http://bioconductor.org/getBioC.R")
biocLite <- function(pkgs, groupName="lite", ...)
     if (missing(pkgs))
         biocinstall(groupName=groupName, ...)
     else
         biocinstall(pkgs=pkgs, groupName=groupName, ...)
}
biocLite("Rgraphviz")
Running biocinstall version 2.1.7 with R version 2.6.0 (under development)
Your version of R requires version 2.1 of Bioconductor.
trying URL 
'http://bioconductor.org/packages/2.1/bioc/bin/macosx/universal/contrib/2.6/Rgraphviz_1.15.9.tgz'

Before the Rgraphviz crash, here is the sessionInfo:
R version 2.6.0 alpha (2007-09-15 r42871)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] Rgraphviz_1.15.9 graph_1.14.2   

loaded via a namespace (and not attached):
[1] cluster_1.11.8 tools_2.6.0

The presumption is this is not polychor but something  about R 2.6.0 for Mac

version information:

platform       i386-apple-darwin8.10.1                 
arch           i386                                    
os             darwin8.10.1                            
system         i386, darwin8.10.1                      
status         alpha                                   
major          2                                       
minor          6.0                                     
year           2007                                    
month          09                                      
day            15                                      
svn rev        42871                                   
language       R                                       
version.string R version 2.6.0 alpha (2007-09-15 r42871)

Crash is reliable.  I am happy to send any more dump information you 
want.  Here is the R traceback

R version 2.6.0 alpha (2007-09-15 r42871)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] polycor_0.7-3 mvtnorm_0.8-1
plychr> set.seed(12345)

plychr> data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2))

plychr> x <- data[,1]

plychr> y <- data[,2]

plychr> cor(x, y)  # sample correlation
[1] 0.5285446

plychr> x <- cut(x, c(-Inf, .75, Inf))

plychr> y <- cut(y, c(-Inf, -1, .5, 1.5, Inf))

plychr> polychor(x, y)  # 2-step estimate

  *** caught bus error ***
address 0x0, cause 'non-existent physical address'

Traceback:
  1: .Fortran("mvtdst", N = as.integer(n), NU = as.integer(df), LOWER 
= as.double(lower),     UPPER = as.double(upper), INFIN = 
as.integer(infin), CORREL = as.double(corrF),     DELTA = 
as.double(delta), MAXPTS = as.integer(maxpts), ABSEPS = 
as.double(abseps),     RELEPS = as.double(releps), error = 
as.double(error), value = as.double(value),     inform = 
as.integer(inform), PACKAGE = "mvtnorm")
  2: mvt(lower = lower, upper = upper, df = 0, corr = corr, delta = 
mean,     maxpts = maxpts, abseps = abseps, releps = releps)
  3: pmvnorm(lower = c(row.cuts[i], col.cuts[j]), upper = c(row.cuts[i 
+     1], col.cuts[j + 1]), corr = R)
  4: binBvn(rho, row.cuts, col.cuts)
  5: f(arg, ...)
  6: function (arg) f(arg, ...)(-0.23606797749979)
  7: optimise(f, interval = c(-1, 1))
  8: polychor(x, y)
  9: eval.with.vis(expr, envir, enclos)
10: eval.with.vis(ei, envir)
11: source(zfile, local, echo = echo, prompt.echo = 
paste(prompt.prefix,     getOption("prompt"), sep = ""), 
continue.echo = paste(prompt.prefix,     getOption("continue"), sep = 
""), verbose = verbose, max.deparse.length = Inf,     encoding = 
encoding, skip.echo = skips)
12: example(polychor)



Bill
At 3:34 PM -0700 9/16/07, Jan de Leeuw wrote:

  
    
  
#
Ben,
At 7:15 PM -0400 9/16/07, Ben Bolker wrote:
At least that solves the polychor problem.  You are right.
I tried it with just the mvtnorm package and the error occurs.

Error trace follows:
R version 2.6.0 alpha (2007-09-15 r42871)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] mvtnorm_0.8-1
pmvnrm> n <- 5

pmvnrm> mean <- rep(0, 5)

pmvnrm> lower <- rep(-1, 5)

pmvnrm> upper <- rep(3, 5)

pmvnrm> corr <- diag(5)

pmvnrm> corr[lower.tri(corr)] <- 0.5

pmvnrm> corr[upper.tri(corr)] <- 0.5

pmvnrm> prob <- pmvnorm(lower, upper, mean, corr)

  *** caught bus error ***
address 0x0, cause 'non-existent physical address'

Traceback:
  1: .Fortran("mvtdst", N = as.integer(n), NU = as.integer(df), LOWER 
= as.double(lower),     UPPER = as.double(upper), INFIN = 
as.integer(infin), CORREL = as.double(corrF),     DELTA = 
as.double(delta), MAXPTS = as.integer(maxpts), ABSEPS = 
as.double(abseps),     RELEPS = as.double(releps), error = 
as.double(error), value = as.double(value),     inform = 
as.integer(inform), PACKAGE = "mvtnorm")
  2: mvt(lower = lower, upper = upper, df = 0, corr = corr, delta = 
mean,     maxpts = maxpts, abseps = abseps, releps = releps)
  3: pmvnorm(lower, upper, mean, corr)
  4: eval.with.vis(expr, envir, enclos)
  5: eval.with.vis(ei, envir)
  6: source(zfile, local, echo = echo, prompt.echo = 
paste(prompt.prefix,     getOption("prompt"), sep = ""), 
continue.echo = paste(prompt.prefix,     getOption("continue"), sep = 
""), verbose = verbose, max.deparse.length = Inf,     encoding = 
encoding, skip.echo = skips)
  7: example(pmvnorm)

Bill

  
    
  
#
Ok, I made it go away.

Following Ben's hint, I reinstalled mvtnorm  from CRAN and polychor 
works perfectly again.

For Rgraphviz, I had not loaded one of the dependencies for graph, 
and although graph did not object, it just crashed.

With a reinstalled mvtnorm,  and Rgraphviz and graph and ..., 
everything works beautifully.

Thanks.  I was unaccustomed to having such an ungraceful exit 
compared to the normal set of warnings.   But that is what happens 
when you try out an alpha release.

Bill
At 6:51 PM -0500 9/16/07, William Revelle wrote: