Jump to content
We've recently updated our Privacy Statement, available here. ×

Error message when calculating Cramer's V correlation analysis


Robert Lelieveld

Recommended Posts

Hi Tibco,

I downloaded the template version 1.1 and replaced the data with my own data table.

On 'The Data' tab, selecting a response and target value is fine.

On 'Predictor Importance' tab, selecting a list of predictors and calculating their strength goes well.

On 'Cat Predictor Correlations' tab, clicking on 'Measure Correlations' provides an error message. Also when I first select some predictors in the 'Act'-section (lower left).

This is the message Spotfire provides:

Could not execute function call.

TIBCO Enterprise Runtime for R returned an error: 'Error in .pearson.x2(cross.classif, expected, yates = correct) : missing value where TRUE/FALSE needed

eval(expr, envir, enclos)

eval(expr, envir, enclos)

withWarnings(apply(nameorder, 2, function(x, Data)

withCallingHandlers(expr, warning = wHandler)

apply(nameorder, 2, function(x, Data)

FUN(X[], Data = Data[i.fac])

cv.test(a, b)

chisq.test(x, y, correct = FALSE)

.pearson.x2(cross.classif, expected, yates = correct)'.

at Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting()

at Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.d__31.MoveNext()

at Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.d__12.MoveNext()

at Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.d__3.MoveNext()When executing this using the original data, all is fine. So I guess there is something in my data.

Where should I look to fix this

Thank you.

Kind regards,

Robert Lelieveld

Link to comment
Share on other sites

  • 1 year later...

Hi,

I realise this is an old post but in case anyone else hits this issue, the script below fixes the issue. The issue is caused when you have too many NA's in your data. I added checks into the Cramer script to solve this. So please replace the Cramer data function code to be:

# Author: Ana Costa e Silva, 21st April 2017

# Updated: Colin Gray Jan 2020 to add checks into chi sq test for NAs

 

 

# Input:

# - Data is table with categorical variables for which we want to compute VCramer correlations as a measure of association

 

# Output

# - VCramerOut is a table with the correlations of every column in Data that has at least two different values

# - resWarningis a string with any warnings produced by the test, namely when data sizes are small for some category combinations

 

 

#------- For debugging -----------------------------------------------------------------------------------------------------------------

 

TimeStamp=paste(date(),Sys.timezone())

datafun='[TERR] VCramer' # change this accordingly

tdir = 'C:/Demo' # place to store diagnostics if it exists (otherwise do nothing)

#if(file.exists(tdir) && file.info(tdir)$isdir) suppressWarnings(try(save(list=ls(), file=paste(tdir,'/data VCramer.RData',sep=''), RFormat=T )))

 

# In your interactive R session, run the following code to load up the saved

# remove(list=ls()); load(file='C:/Demo/data VCramer.RData'); print(datafun); print(TimeStamp)

 

 

#------- Begin function definitions ---------------------------------------------------------------------------------------------------

 

# Applies the test to pairs of columns

cv.test = function(x,y) {

CV = sqrt(chisq.test(x, y, correct=FALSE)$statistic /

(length(x) * (min(length(unique(x)),length(unique(y))) - 1)))

#print.noquote("Cramr V / Phi:")

return(as.numeric(CV))

}

 

 

# Captures warnings

withWarnings

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...