[R] error in hetcor function (polycor package)?

John Fox jfox at mcmaster.ca
Sat Dec 2 00:19:56 CET 2006


Dear Brendan,

That's curious, because the use argument to hetcor() works fine for me (see
below). Is it possible that you tried to use this argument without
specifying a data frame as the first argument to hetcor? If so, please see
?hetcor. If not, it would help to have an example.

I hope this helps,
 John

------------ snip -------------

> set.seed(12345) # adapting the example in ?hetcor
> R <- matrix(0, 4, 4)
> R[upper.tri(R)] <- runif(6)
> diag(R) <- 1
> R <- cov2cor(t(R) %*% R)
> round(R, 4)  # population correlations
       [,1]   [,2]   [,3]   [,4]
[1,] 1.0000 0.5848 0.5718 0.6233
[2,] 0.5848 1.0000 0.7374 0.6249
[3,] 0.5718 0.7374 1.0000 0.5923
[4,] 0.6233 0.6249 0.5923 1.0000
> data <- rmvnorm(1000, rep(0, 4), R)
> round(cor(data), 4)   # sample correlations
       [,1]   [,2]   [,3]   [,4]
[1,] 1.0000 0.5933 0.5659 0.6088
[2,] 0.5933 1.0000 0.7334 0.6230
[3,] 0.5659 0.7334 1.0000 0.5802
[4,] 0.6088 0.6230 0.5802 1.0000
> x1 <- data[,1]
> x2 <- data[,2]
> y1 <- cut(data[,3], c(-Inf, .75, Inf))
> y2 <- cut(data[,4], c(-Inf, -1, .5, 1.5, Inf))
> data <- data.frame(x1, x2, y1, y2)
> data[1,1] <- NA
> hetcor(data) 

Two-Step Estimates

Correlations/Type of Correlation:
       x1      x2         y1         y2
x1      1 Pearson Polyserial Polyserial
x2 0.5932       1 Polyserial Polyserial
y1 0.5952  0.7409          1 Polychoric
y2  0.624  0.6316     0.5708          1

Standard Errors:
        x1      x2     y1
x1                       
x2 0.02053               
y1 0.03092 0.02296       
y2 0.02027 0.01995 0.0374

n = 999 

P-values for Tests of Bivariate Normality:
       x1     x2      y1
x1                      
x2 0.4782               
y1 0.4023 0.8871        
y2 0.1166 0.5077 0.05526

> hetcor(data, use = "complete.obs")

Two-Step Estimates

Correlations/Type of Correlation:
       x1      x2         y1         y2
x1      1 Pearson Polyserial Polyserial
x2 0.5932       1 Polyserial Polyserial
y1 0.5952  0.7409          1 Polychoric
y2  0.624  0.6316     0.5708          1

Standard Errors:
        x1      x2     y1
x1                       
x2 0.02053               
y1 0.03092 0.02296       
y2 0.02027 0.01995 0.0374

n = 999 

P-values for Tests of Bivariate Normality:
       x1     x2      y1
x1                      
x2 0.4782               
y1 0.4023 0.8871        
y2 0.1166 0.5077 0.05526

> hetcor(data, use = "pairwise.complete.obs")

Two-Step Estimates

Correlations/Type of Correlation:
       x1      x2         y1         y2
x1      1 Pearson Polyserial Polyserial
x2 0.5932       1 Polyserial Polyserial
y1 0.5952  0.7409          1 Polychoric
y2  0.624  0.6317     0.5711          1

Standard Errors/Numbers of Observations:
        x1      x2      y1   y2
x1     999     999     999  999
x2 0.02053    1000    1000 1000
y1 0.03092 0.02295    1000 1000
y2 0.02027 0.01994 0.03738 1000

P-values for Tests of Bivariate Normality:
       x1     x2      y1
x1                      
x2 0.4952               
y1 0.4023  0.878        
y2 0.1166 0.5255 0.05615

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

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of BRENDAN KLICK
> Sent: Friday, December 01, 2006 1:42 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] error in hetcor function (polycor package)?
> 
> I have been using the hetcor function in the polycor package. 
>  When I don't specify the use option everything runs 
> smoothly.  However, when I specify use either as 
> "pairwise.complete.obs" or "complete.obs" I get this error
>  
> Error in optim(rho, f, control = control, hessian = TRUE, method =
> "BFGS") : 
>         non-finite value supplied by optim
> 
> Is this an error in the hetcor function or am I missing something. 
> Thanks for your help.
>  
> Brendan Klick
> Johns Hopkins University School of Medicine bklick1 at jhmi.edu
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list