Data Science Pilot Action Set
Linear and Nonlinear Correlation Analysis Using the exploreCorrelation Action
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
The following DATA step creates the reference data table mycas.dmagecr in your CAS session, keeping only the age, amount, coapp, duration, foreign, job, and good_bad variables. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.dmagecr;
set sampsio.dmagecr;
run;
The following statements run the exploreCorrelation action to analyze the correlation structure among the input variables. The action outputs a data table that contains the specified correlation statistics. Note that you can specify different sets of statistics for the nominal-nominal, nominal-interval (interval-nominal), and interval-interval pairs of variables. The action outputs the results of the analysis in an output data table named correlation_out.
proc cas;
loadactionset "dataSciencePilot";
dataSciencePilot.exploreCorrelation
/ table = "DMAGECR"
casOut = {name = "CORRELATION_OUT",
replace = True}
stats = {nominalNominal={"mi", "su"},
nominalInterval = {"mi", "su", "ftest"},
intervalInterval = {"mi", "su", "pearson"}}
inputs = {{name = "age"},
{name = "amount"},
{name = "coapp"},
{name = "duration"},
{name = "foreign"},
{name = "job"}}
nominals = {"coapp", "foreign", "job"}
;
run;
fetch / table = "CORRELATION_OUT";
run;
quit;
The table parameter names the input reference data table. The casOut parameter names the output data table. The stats parameter specifies the set of correlation statistics to be computed for the three types of variable pairs: nominal-nominal, nominal-interval (interval-nominal), and interval-interval. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
The CAS output table is shown in Output 11.4.1.
Output 11.4.1: Linear and Nonlinear Correlation
| Selected Rows from Table CORRELATION_OUT | ||||||||
|---|---|---|---|---|---|---|---|---|
| _Index_ | FirstVariable | SecondVariable | Type | FTest | ProbF | Pearson | MI | SU |
| 1 | age | coapp | _ni_1 | 0.4760598374 | 0.6213674487 | . | 0.0569117234 | 0.0203743996 |
| 2 | age | foreign | _ni_2 | 0.0377654221 | 0.8459544813 | . | 0.0366299985 | 0.0135726197 |
| 3 | age | job | _ni_3 | 9.2311591127 | 5.0223212E-6 | . | 0.1439877347 | 0.0449737593 |
| 4 | amount | age | _ii_4 | . | . | 0.0327164167 | 0.157533392 | 0.0415035709 |
| 5 | amount | coapp | _ni_1 | 5.0520611592 | 0.0065608658 | . | 0.1117193311 | 0.033948961 |
| 6 | amount | foreign | _ni_2 | 2.5062714187 | 0.1137107593 | . | 0.070317726 | 0.0204682618 |
| 7 | amount | job | _ni_3 | 41.857737606 | 1.771472E-25 | . | 0.1972747899 | 0.0559120431 |
| 8 | duration | age | _ii_4 | . | . | -0.036136374 | 0.0877997891 | 0.0254065779 |
| 9 | duration | amount | _ii_5 | . | . | 0.6249841983 | 0.4977154476 | 0.1435409495 |
| 10 | duration | coapp | _ni_1 | 1.1698717128 | 0.3108324871 | . | 0.022866107 | 0.0113106304 |
| 11 | duration | foreign | _ni_2 | 19.431116448 | 0.000011559 | . | 0.0401058248 | 0.0210146317 |
| 12 | duration | job | _ni_3 | 16.675218685 | 1.41484E-10 | . | 0.0704659213 | 0.0290523974 |
| 13 | foreign | coapp | _nn_1 | . | . | . | 0.0073658606 | 0.01921124 |
| 14 | job | coapp | _nn_1 | . | . | . | 0.0121146554 | 0.012413386 |
| 15 | job | foreign | _nn_2 | . | . | . | 0.0072576768 | 0.0088412863 |
Linear and Nonlinear Correlation Analysis Using the exploreCorrelation Action
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="dmagecr.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following statements run the exploreCorrelation action to analyze the correlation structure among the input variables. The action outputs a data table that contains the specified correlation statistics. Note that you can specify different sets of statistics for the nominal-nominal, nominal-interval (interval-nominal), and interval-interval pairs of variables. The action outputs the results of the analysis in an output data table named correlation_out.
s:loadactionset{actionset="dataSciencePilot"}
s:dataSciencePilot_exploreCorrelation {
table = {name ="DMAGECR"},
casOut = {name = "CORRELATION_OUT",
replace = True},
stats = {nominalNominal={"mi", "su"},
nominalInterval = {"mi", "su", "ftest"},
intervalInterval = {"mi", "su", "pearson"}},
inputs = {{name = "age"},
{name = "amount"},
{name = "coapp"},
{name = "duration"},
{name = "foreign"},
{name = "job"}},
nominals = {"coapp", "foreign", "job"}
}
s:fetech{table = {name = "CORRELATION_OUT"}}
The table parameter names the input reference data table. The casOut parameter names the output data table. The stats parameter specifies the set of correlation statistics to be computed for the three types of variable pairs: nominal-nominal, nominal-interval (interval-nominal), and interval-interval. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.
Linear and Nonlinear Correlation Analysis Using the exploreCorrelation Action
This section contains R code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:
m <- cas.read.csv(s, "dmagecr.csv", casOut=list(name="dmagecr"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
The following statements run the exploreCorrelation action to analyze the correlation structure among the input variables. The action outputs a data table that contains the specified correlation statistics. Note that you can specify different sets of statistics for the nominal-nominal, nominal-interval (interval-nominal), and interval-interval pairs of variables. The action outputs the results of the analysis in an output data table named correlation_out.
cas.loadActionSet(s,"dataSciencePilot")
cas.dataSciencePilot.exploreCorrelation(
s,
table = list(name ="DMAGECR"),
casOut = list(name = "CORRELATION_OUT",
replace = True),
stats = list(list(nominalNominal=list("mi", "su")),
list(nominalNominal=list("mi", "su", "ftest")),
list(nominalNominal=list("mi", "su", "pearson"))),
inputs = list("age",
"amount",
"coapp",
"duration",
"foreign",
"job"),
nominals = list("coapp",
"foreign",
"job")
)
cas.fetch(s, table = list(name = "CORRELATION_OUT"))
The table parameter names the input reference data table. The casOut parameter names the output data table. The stats parameter specifies the set of correlation statistics to be computed for the three types of variable pairs: nominal-nominal, nominal-interval (interval-nominal), and interval-interval. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.
Linear and Nonlinear Correlation Analysis Using the exploreCorrelation Action
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the dmagecr data to the comma-separated-value (CSV) file dmagecr.csv and then use the following code to load the CSV file into CAS:
s.upload_file('dmagecr.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following statements run the exploreCorrelation action to analyze the correlation structure among the input variables. The action outputs a data table that contains the specified correlation statistics. Note that you can specify different sets of statistics for the nominal-nominal, nominal-interval (interval-nominal), and interval-interval pairs of variables. The action outputs the results of the analysis in an output data table named correlation_out.
s.loadactionset(actionset="dataSciencePilot")
s.dataSciencePilot.exploreCorrelation(
table = {"name" : "DMAGECR"},
casOut = {"name" : "CORRELATION_OUT", "replace" : True},
stats = {"nominalNominal":["mi", "su"],
"nominalInterval":["mi", "su", "ftest"],
"intervalInterval":["mi", "su", "pearson"]},
inputs = ["age", "amount", "coapp", "duration", "foreign", "job"],
nominals = ["coapp", "foreign", "job"]
)
s.fetch(table = {"name":"CORRELATION_OUT"})
The table parameter names the input reference data table. The casOut parameter names the output data table. The stats parameter specifies the set of correlation statistics to be computed for the three types of variable pairs: nominal-nominal, nominal-interval (interval-nominal), and interval-interval. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.