Contingency
Example 1
Summary: Generates a contingency analysis to display the distribution of nominal variables, specifically 'Relapsed' and 'Alcohol Consumption', with frequency counts, total percentages, column percentages, row percentages, and hides expected values.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :Relapsed ),
X( :Alcohol Consumption ),
Freq( :Count ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
)
);
Code Explanation:
- Open table.
- Create contingency analysis.
- Set Y variable.
- Set X variable.
- Use frequency column.
- Display count.
- Display total percentage.
- Display column percentage.
- Display row percentage.
- Hide expected values.
Example 2
Summary: Performs contingency analysis on three different variables (Claim Y/N, City(Y/N), and Rating Class) from a data table, generating contingency tables with various options and sending the results to a report.
Code:
// Contingency (Claim Y/N)
// Open data table
dt = Open("data_table.jmp");
// Contingency (Claim Y/N)
Contingency(
Y( :"Claim(Y/N)"n ),
X( :AgeClass ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 0 ),
Row %( 0 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
),
SendToReport(
Dispatch( {}, "Contingency Table",
OutlineBox,
Close( 1 )
)
)
);
Contingency(
Y( :"Claim(Y/N)"n ),
X( :"City(Y/N)"n ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 0 ),
Row %( 0 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
),
SendToReport(
Dispatch( {}, "Contingency Table",
OutlineBox,
Close( 1 )
)
)
);
Contingency(
Y( :"Claim(Y/N)"n ),
X( :Rating Class ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 0 ),
Row %( 0 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
),
SendToReport(
Dispatch( {}, "Contingency Table",
OutlineBox,
Close( 1 )
)
)
);
Code Explanation:
- Open data table.
- Perform contingency analysis.
- Set Y variable.
- Set X variable (AgeClass).
- Configure contingency table options.
- Hide contingency table outline.
- Perform second contingency analysis.
- Set Y variable.
- Set X variable (City(Y/N)).
- Configure and hide contingency table outline.
Example 3
Summary: Generates a contingency table to analyze the distribution of nominal variables, specifically examining the relationship between age and sex.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :age ),
X( :sex ),
Crosstabs(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
"Cell Chi^2"n( 0 )
)
);
Code Explanation:
- Open table.
- Create contingency analysis.
- Set Y variable to age.
- Set X variable to sex.
- Enable count display.
- Enable total percentage display.
- Enable column percentage display.
- Enable row percentage display.
- Disable expected values display.
- Disable deviation display.
Example 4
Summary: Opens a data table, performs contingency analysis with Country as the Y variable and Type as the X variable, and displays counts, total percentages, column percentages, and row percentages in a contingency table.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :Country ),
X( :Type ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
)
);
Code Explanation:
- Open data table.
- Perform contingency analysis.
- Set Y variable as Country.
- Set X variable as Type.
- Configure contingency table options.
- Display counts.
- Display total percentages.
- Display column percentages.
- Display row percentages.
- Do not display expected values.
Example 5
Summary: Opens a data table, performs a contingency analysis with nominal variables, and visualizes the results.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :type ),
X( :marital status )
);
Code Explanation:
- Open data table.
- Run contingency analysis.
- Set Y variable.
- Set X variable.
Example 6
Summary: Generates distributions of nominal variables by performing a contingency analysis on the specified response and predictor variables, with frequency counts and correspondence analysis enabled.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :Response ),
X( :Cheese ),
Freq( :Count ),
Crosstabs( 0 ),
Tests( 0 ),
Correspondence Analysis( 1 )
);
Code Explanation:
- Open data table;
- Create contingency analysis.
- Set response variable.
- Set predictor variable.
- Specify frequency column.
- Disable crosstabs display.
- Disable tests display.
- Enable correspondence analysis.
Example 7
Summary: Opens a data table, defines a contingency analysis with a nominal response variable and predictor variable, configures the contingency table display, and disables count and percentage displays.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :Lung Cancer ),
X( :Smoker ),
Freq( :Count ),
Contingency Table(
Count( 1 ),
Total %( 0 ),
Col %( 0 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
),
Tests( 0 )
);
Code Explanation:
- Open data table.
- Define contingency analysis.
- Set response variable.
- Set predictor variable.
- Set frequency variable.
- Configure contingency table display.
- Disable count display.
- Disable total percentage display.
- Disable column percentage display.
- Enable row percentage display.
Example 8
Summary: Generates a contingency analysis to visualize the distribution of nominal variables in a data table, with options for crosstabs and percentages.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :To ),
X( :From ),
Crosstabs(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
"Cell Chi^2"n( 0 )
)
);
Code Explanation:
- Open data table.
- Create contingency analysis.
- Set Y variable to "To".
- Set X variable to "From".
- Configure crosstabs options.
- Count occurrences.
- Calculate total percentages.
- Calculate column percentages.
- Calculate row percentages.
- Disable expected values.
Example 9
Summary: Generates a contingency analysis to examine the relationship between 'On Time' and 'Clinic', with frequency as the third dimension, displaying various statistics such as count, total percentage, column percentage, row percentage, expected values, deviation, cell chi-square, and cumulative percentages.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( :On Time ),
X( :Clinic ),
Freq( :Frequency ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Analysis of Means for Proportions(
1,
Show Summary Report( 1 ),
Switch Response Level for Proportion(
1
)
),
Contingency(
Y( :On Time ),
X( :Clinic ),
Freq( :Frequency ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Analysis of Means for Proportions(
1,
Show Summary Report( 1 ),
Switch Response Level for Proportion(
1
)
)
)
);
Code Explanation:
- Open table.
- Create contingency analysis.
- Set Y variable.
- Set X variable.
- Use frequency column.
- Configure contingency table.
- Enable count display.
- Enable total percentage display.
- Enable column percentage display.
- Enable row percentage display.
Example 10
Summary: Opens a data table, performs a contingency analysis with a specific agreement statistic, and generates distributions of nominal variables.
Code:
// Contingency
// Open data table
dt = Open("data_table.jmp");
// Contingency
Contingency(
Y( 2 ),
X( 1 ),
Freq( 3 ),
Agreement Statistic( 1 )
);
Code Explanation:
- Open table.
- Run contingency analysis.
- Set response variable.
- Set factor variable.
- Use frequency column.
- Calculate agreement statistic.
Example 11
Summary: Generates a mosaic plot to visualize the distribution of nominal variables, specifically 'Carrier Code' by 'Airport', using Contingency analysis and sending it to a report.
Code:
Open("data_table.jmp");
Contingency( Y( :Carrier Code ), X( :Airport ), Contingency Table( 0 ), Tests( 0 ) );
Contingency(
Y( :Carrier Code ),
X( :Airport ),
Contingency Table( 0 ),
Tests( 0 ),
SendToReport( Dispatch( {"Mosaic Plot"}, "1", ScaleBox, {Label Row( {Set Font Size( 18 ), Set Font Style( "Plain" )} )} ) )
);
Code Explanation:
- Open data table;
- Create contingency table.
- Redraw contingency table.
- Set font size to 18.
- Set font style to plain.
Example 12
Summary: Creates a contingency table for nominal variables, utilizing a Column Switcher to dynamically switch between columns.
Code:
Open("data_table.jmp");
obj = Contingency( Y( :size ), X( :marital status ) );
ColumnSwitcherObject = obj << Column Switcher( :marital status, {:sex, :country, :marital status} );
Code Explanation:
- Open data table;
- Create contingency object.
- Add column switcher.
Example 13
Summary: Creates a contingency analysis object to generate distributions of nominal variables, utilizing Column Switcher for interactive filtering and setting size.
Code:
dt = Open("data_table.jmp");
obj = Contingency( Y( :size ), X( :marital status ) );
ColumnSwitcherObject = obj << Column Switcher( :marital status, {:sex, :country, :marital status} );
ColumnSwitcherObject << Set Size( 200 );
Code Explanation:
- Open data table;
- Create contingency analysis object.
- Initialize Column Switcher.
- Set size of Column Switcher.
Example 14
Summary: Generates a contingency table, correspondence analysis, and horizontal mosaic plot to analyze the relationship between sex and age in a data set, while also conducting Cochran-Armitage trend tests.
Code:
dt = Open("data_table.jmp");
Contingency(
Y( :sex ),
X( :age ),
Contingency Table,
Correspondence Analysis( 1 ),
Horizontal Mosaic( 1 ),
Cochran Armitage Trend Test( 1 ),
SendToReport(
Dispatch( {"Mosaic Plot"}, "", NomAxisBox( 2 ), {Set Width( 20 ), Set Height( 320 )} ),
Dispatch( {"Correspondence Analysis"}, "1", ScaleBox, {Format( "Custom", Formula( Round( Cauchy Density( value ), 2 ) ), 12 )} ),
Dispatch( {"Correspondence Analysis"}, "2", ScaleBox, {Format( "Custom", Formula( Round( Gamma Density( value ), 2 ) ), 12 )} )
)
);
Code Explanation:
- Open data table;
- Create contingency analysis.
- Set Y variable as "sex".
- Set X variable as "age".
- Generate contingency table.
- Perform correspondence analysis.
- Create horizontal mosaic plot.
- Conduct Cochran-Armitage trend test.
- Adjust mosaic plot size.
- Customize correspondence analysis formats.
Example 15
Summary: Generates a contingency table to analyze the distribution of nominal variables, specifically 'name' and 'sex', filtered by age 12.
Code:
dt = Open("data_table.jmp");
Contingency( Y( :name ), X( :sex ), Contingency Table, Where( :age == 12 ) );
Code Explanation:
- Open data table;
- Create contingency table.
- Set Y variable to name.
- Set X variable to sex.
- Apply mosaic plot.
- Filter data where age equals 12.
Example 16
Summary: Generates a contingency table analysis for nominal variables, filtering rows based on height and grouping results by age.
Code:
dt = Open("data_table.jmp");
dt << Contingency( Y( :name ), X( :sex ), Contingency Table( 0 ), Tests( 0 ), Where( :height < 63 ), By( :age ) );
Code Explanation:
- Open data table;
- Create contingency analysis.
- Set Y variable to "name".
- Set X variable to "sex".
- Disable contingency table display.
- Disable tests display.
- Filter rows where height < 63.
- Group results by "age".
Example 17
Summary: Runs a contingency analysis to visualize the distribution of nominal variables, enabling correspondence analysis and analysis of means for proportions with point options set to show needles.
Code:
Open("data_table.jmp");
Contingency(
Y( :age ),
X( :sex ),
Contingency Table( 0 ),
Mosaic Plot( 0 ),
Tests( 0 ),
Correspondence Analysis( 1 ),
Analysis of Means for Proportions( 1, Show Decision Limits( 0 ), Point Options( "Show Needles" ) ),
SendToReport( Dispatch( {}, "Analysis of Means for Proportions", OutlineBox, {Close( 1 )} ) )
);
Code Explanation:
- Open data table;
- Perform contingency analysis.
- Set Y variable to age.
- Set X variable to sex.
- Disable contingency table.
- Disable mosaic plot.
- Disable tests.
- Enable correspondence analysis.
- Enable analysis of means for proportions.
- Hide decision limits.
- Show needles in point options.
- Close analysis of means for proportions outline.
Example 18
Summary: Analyze Age by sex in a contingency table, providing a summary of the relationship between these two nominal variables.
Code:
Names Default To Here( 1 );
dt = Open("data_table.jmp");
obj = Contingency( Y( :Age ), X( :sex ) );
Code Explanation:
- Set default names.
- Open data table;
- Create contingency object.
- Analyze Age by sex.
Example 19
Summary: Generates contingency tables for nominal variables, filtering data by height and grouping results by age.
Code:
Open("data_table.jmp");
Contingency( Y( :name ), X( :sex ), Contingency Table( 0 ), Tests( 0 ), Where( :height < 63 ), By( :age ) );
Code Explanation:
- Open data table;
- Run contingency analysis.
- Set response variable.
- Set factor variable.
- Disable contingency table display.
- Disable statistical tests.
- Apply height filter.
- Group by age variable.
Example 20
Summary: Analyze nominal variables by generating distributions and enabling correspondence analysis and measures of association in JMP.
Code:
dt under test = Open("data_table.jmp");
obj = Contingency(
Y( :age ),
X( :sex ),
Contingency Table( 0 ),
Mosaic Plot( 0 ),
Tests( 0 ),
Correspondence Analysis( 1 ),
Measures of Association( 1 ),
SendToReport(
Dispatch( {}, "Contingency Analysis of age By sex", OutlineBox, {Set Title( "Correspondence Analysis, Measures of Association" )} ),
Dispatch( {"Correspondence Analysis"}, "Details", OutlineBox, {Close( 0 )} )
)
);
Code Explanation:
- Open table.
- Create contingency object.
- Set Y variable.
- Set X variable.
- Disable contingency table.
- Disable mosaic plot.
- Disable tests.
- Enable correspondence analysis.
- Enable measures of association.
- Set report title and close details.
Example 21
Summary: Generates contingency tables to analyze nominal variables, specifically 'age' and 'sex', with configurable crosstabs options.
Code:
dt under test = Open("data_table.jmp");
obj = Contingency(
Y( :age ),
X( :sex ),
Crosstabs( Count( 1 ), Total %( 1 ), Col %( 1 ), Row %( 1 ), Expected( 0 ), Deviation( 0 ), Name( "Cell Chi^2" )(0) )
);
Code Explanation:
- Open data table;
- Create contingency object.
- Set Y variable to "age".
- Set X variable to "sex".
- Configure crosstabs options.
- Count occurrences in cells.
- Calculate total percentages.
- Calculate column percentages.
- Calculate row percentages.
- Disable expected values.
Example 22
Summary: Generates contingency tables for nominal variables, enabling automatic recalculation and certified statistics calculation.
Code:
dt = Open("data_table.jmp");
cont = dt << Contingency(
Y( :age ),
X( :sex ),
Crosstabs( Count( 1 ), Total %( 1 ), Col %( 1 ), Row %( 1 ), Expected( 0 ), Deviation( 0 ), Name( "Cell Chi^2" )(0) )
);
cont << Automatic Recalc( 1 );
dt << select where( :age == 12 | :age == 13 );
dt << Hide and Exclude( 1 );
contTable1 = cont << Make into Data table;
sumStats1 = contTable1 << get as matrix;
certStats1 = [5 2 2 1,
20 8 8 4,
41.6666666666667 28.5714285714286 66.6666666666667 33.3333333333333,
50 20 20 10,
7 5 1 2,
28 20 4 8,
58.3333333333333 71.4285714285714 33.3333333333333 66.6666666666667,
46.6666666666667 33.3333333333333 6.66666666666667 13.3333333333333];
dt << clear row states;
dt << select Where( :age == 12 | :age == 17 );
dt << Hide and Exclude( 1 );
contTable2 = cont << Make into Data Table;
sumStats2 = contTable2 << get as matrix;
certSTats2 = [3 5 2 2,
10.3448275862069 17.2413793103448 6.89655172413793 6.89655172413793,
42.8571428571429 41.6666666666667 28.5714285714286 66.6666666666667,
25 41.6666666666667 16.6666666666667 16.6666666666667,
4 7 5 1,
13.7931034482759 24.1379310344828 17.2413793103448 3.44827586206897,
57.1428571428572 58.3333333333333 71.4285714285714 33.3333333333333,
23.5294117647059 41.1764705882353 29.4117647058824 5.88235294117647];
Close( dt, no save );
Code Explanation:
- Open data table.
- Create contingency table.
- Enable automatic recalculation.
- Select rows where age is 12 or 13.
- Hide and exclude selected rows.
- Convert contingency table to data table.
- Retrieve table as matrix.
- Define certified statistics for first selection.
- Clear row states in original table.
- Select rows where age is 12 or 17.
- Hide and exclude selected rows.
- Convert contingency table to data table again.
- Retrieve table as matrix.
- Define certified statistics for second selection.
- Close original table without saving.
Example 23
Summary: Generates contingency tables and summary statistics for nominal variables, enabling interactive filtering by age group.
Code:
dt = Open("data_table.jmp");
cont = dt << Contingency(
Y( :age ),
X( :sex ),
Crosstabs( Count( 1 ), Total %( 1 ), Col %( 1 ), Row %( 1 ), Expected( 0 ), Deviation( 0 ), Name( "Cell Chi^2" )(0) )
);
cont << Automatic Recalc( 1 );
dt << select where( :age == 12 | :age == 13 );
dt << Hide and Exclude( 1 );
contTable1 = cont << Make into Data table;
sumStats1 = contTable1 << get as matrix;
certStats1 = [5 2 2 1,
20 8 8 4,
41.6666666666667 28.5714285714286 66.6666666666667 33.3333333333333,
50 20 20 10,
7 5 1 2,
28 20 4 8,
58.3333333333333 71.4285714285714 33.3333333333333 66.6666666666667,
46.6666666666667 33.3333333333333 6.66666666666667 13.3333333333333];
dt << clear row states;
dt << select Where( :age == 12 | :age == 17 );
dt << Hide and Exclude( 1 );
contTable2 = cont << Make into Data Table;
sumStats2 = contTable2 << get as matrix;
certSTats2 = [3 5 2 2,
10.3448275862069 17.2413793103448 6.89655172413793 6.89655172413793,
42.8571428571429 41.6666666666667 28.5714285714286 66.6666666666667,
25 41.6666666666667 16.6666666666667 16.6666666666667,
4 7 5 1,
13.7931034482759 24.1379310344828 17.2413793103448 3.44827586206897,
57.1428571428572 58.3333333333333 71.4285714285714 33.3333333333333,
23.5294117647059 41.1764705882353 29.4117647058824 5.88235294117647];
Code Explanation:
- Open data table.
- Create contingency table.
- Enable automatic recalculation.
- Select specific rows by age.
- Hide and exclude selected rows.
- Convert contingency table to data table.
- Extract summary statistics as matrix.
- Define certified statistics for comparison.
- Clear previous row states.
- Select different rows by age.
- Hide and exclude new selected rows.
- Convert new contingency table to data table.
- Extract new summary statistics as matrix.
- Define new certified statistics for comparison.
Example 24
Summary: Generates a contingency table and Cochran-Mantel-Haenszel test for analyzing the relationship between age and sex, utilizing the Contingency platform in JMP.
Code:
dt = Open("data_table.jmp");
obj = dt << Contingency(
Y( :age ),
X( :sex ),
Contingency Table( 0 ),
Mosaic Plot( 0 ),
Tests( 0 ),
Cochran Mantel Haenszel( :sex ),
Measures of Association( 1 )
);
rpt = Report( obj );
obj2 = obj << redo analysis;
rpt2 = Report( obj2 );
Code Explanation:
- Open data table;
- Create contingency object.
- Set Y variable to age.
- Set X variable to sex.
- Disable contingency table.
- Disable mosaic plot.
- Disable tests.
- Enable Cochran-Mantel-Haenszel test.
- Enable measures of association.
- Redo analysis and report.
Example 25
Summary: Calculates and visualizes risk differences in a contingency table, utilizing the Contingency platform to analyze the relationship between Lung Cancer and Smoker status.
Code:
dt = Open("data_table.jmp");
obj = dt << Contingency(
Y( :Lung Cancer ),
X( :Smoker ),
Freq( :Count ),
Contingency Table( Count( 1 ), Total %( 0 ), Col %( 0 ), Row %( 1 ) ),
Risk Difference( 1 )
);
rpt = Report( obj );
act_val = rpt["Risk Difference", Table Box( 1 )] << get as matrix;
exp_val = [-0.251700298953662 -0.351766340417453 -0.151634257489871];
Code Explanation:
- Open data table;
- Create contingency object.
- Set response variable: Lung Cancer.
- Set factor variable: Smoker.
- Set frequency variable: Count.
- Configure contingency table display.
- Enable risk difference calculation.
- Generate report from object.
- Extract risk difference values.
- Define expected risk difference values.
Example 26
Summary: Creates a contingency table with Fisher's Exact Test and filters data by height range using Local Data Filter.
Code:
dt = Open("data_table.jmp");
obj = dt << Contingency( Y( :age ), X( :sex ), Fisher's Exact Test( 1 ) );
obj << Local Data Filter( Add Filter( columns( :height ), Where( :height >= 56.1 & :height <= 58.2 ) ) );
Code Explanation:
- Open data table;
- Create contingency table.
- Apply Fisher's Exact Test.
- Add local data filter.
- Filter height between 56.1 and 58.2.
Example 27
Summary: Analyze a contingency table to test for trends in nominal variables, extracting Jonckheere-Terpstra test statistics and performing one-way ANOVA on height.
Code:
dt = Open("data_table.jmp");
obj = dt << Contingency( Y( :sex ), X( :age ), Jonckheere Terpstra Test( 1 ) );
rpt = Report( obj );
jtstat_act = (rpt["Jonckheere-Terpstra Test", Number Col Box( "JT Statistic" )] << Get)[1];
jtz_act = (rpt["Jonckheere-Terpstra Test", Number Col Box( "Z" )] << Get)[1];
jtprob_act = (rpt["Jonckheere-Terpstra Test", Number Col Box( "Prob>Z" )] << Get)[1];
jtprob2sided_act = (rpt["Jonckheere-Terpstra Test", Number Col Box( "Prob>|Z|" )] << Get)[1];
jtstat_exp = 349.0000;
jtz_exp = 0.8350;
jtprob_exp = 0.2019;
jtprob2sided_exp = 0.4037;
obj2 = dt << Oneway( Y( :Height ), X( :age ) );
obj2 << Jonckheere Terpstra Test( 1 );
rpt2 = Report( obj2 );
Code Explanation:
- Open data table;
- Create contingency table analysis.
- Extract Jonckheere-Terpstra test statistics.
- Define expected test statistics.
- Perform one-way ANOVA on height.
- Apply Jonckheere-Terpstra test to ANOVA.
Example 28
Summary: Runs the Cochran-Armitage trend test to analyze the relationship between nominal variables, utilizing a Contingency table and generating a report object.
Code:
car = Open("data_table.jmp");
ct = Contingency( Y( :sex ), X( :country ) );
ct << Exact Cochran Armitage Trend Test( 1 );
rpt = Report( ct );
jrn = rpt[Outline Box( "Cochran Armitage Trend Test" )] << get journal;
ct << close window;
Delete Symbols( ct, rpt, jrn, exout, scr );
Code Explanation:
- Open data table;
- Create contingency table.
- Perform Cochran-Armitage test.
- Generate report object.
- Extract Cochran-Armitage trend test results.
- Close contingency table window.
- Delete unused symbols.
Contingency using New Window
Example 1
Summary: Performs multiple correspondence analysis with supplementary rows for subject and gender, generating detailed coordinates and scaling for the first three dimensions, and visualizes relationships between variables using contingency tables, logistic regressions, and mosaic plots.
Code:
// Two Way Relationships
// Open data table
dt = Open("data_table.jmp");
// Two Way Relationships
New Window(
"bands.data- Fit Y by X of band type",
H List Box(
Contingency(
Y( :Banding? ),
X( :paper type ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
)
),
Contingency(
Y( :Banding? ),
X( :press type ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
),
SendToReport(
Dispatch( {"Mosaic Plot"},
"", NomAxisBox,
Rotated Tick Labels(
1
)
)
)
),
Contingency(
Y( :Banding? ),
X( :press ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 )
)
),
Logistic(
Y( :Banding? ),
X( :viscosity ),
Show Points( 0 ),
Show Rate Curve( 1 ),
SendToReport(
Dispatch( {}, "1",
ScaleBox,
{
Min(
31.7771084337349
)}
)
)
),
Logistic(
Y( :Banding? ),
X( :ink temperature ),
Show Points( 0 ),
Show Rate Curve( 1 )
),
Logistic(
Y( :Banding? ),
X( :humidity ),
Show Points( 0 ),
Show Rate Curve( 1 )
),
Logistic(
Y( :Banding? ),
X( :press speed ),
Show Points( 0 ),
Show Rate Curve( 1 )
),
Logistic(
Y( :Banding? ),
X( :hardener ),
Show Points( 0 ),
Show Rate Curve( 1 )
),
Logistic(
Y( :Banding? ),
X( :roller durometer ),
Show Points( 0 ),
Show Rate Curve( 1 )
),
Logistic(
Y( :Banding? ),
X( :anode space ratio ),
Show Points( 0 ),
Show Rate Curve( 1 )
)
)
);
Code Explanation:
- Open table.
- Create new window.
- Add horizontal list box.
- Insert contingency analysis for paper type.
- Insert contingency analysis for press type.
- Rotate mosaic plot tick labels.
- Insert contingency analysis for press.
- Insert logistic regression for viscosity.
- Set minimum scale for viscosity.
- Insert logistic regressions for other variables.
Example 2
Summary: Creates a new window with two contingency analyses, one for marital status and another for country, using Column Switchers to enable interactive filtering.
Code:
dt = Open("data_table.jmp");
New Window( "CS broadcast",
H List Box( c1 = dt << Contingency( Y( :size ), X( :marital status ), ), c2 = dt << Contingency( Y( :size ), X( :country ), ) )
);
cs1 = c1 << Column Switcher( :marital status, {:sex, :country, :marital status} );
cs2 = c2 << Column Switcher( :country, {:sex, :country, :marital status} );
Code Explanation:
- Open data table;
- Create new window titled "CS broadcast".
- Add horizontal list box with two items.
- First item: contingency analysis with size as Y, marital status as X.
- Second item: contingency analysis with size as Y, country as X.
- Assign first contingency analysis to cs1.
- Assign second contingency analysis to cs2.
- Add column switcher to cs1 for marital status.
- Set switchable columns for cs1: sex, country, marital status.
- Add column switcher to cs2 for country.
- Set switchable columns for cs2: sex, country, marital status.
Example 3
Summary: Creates a new window with two contingency tables, allowing for interactive exploration and broadcasting of results.
Code:
Names Default To Here( 1 );
dt = Open("data_table.jmp");
New Window( "CS broadcast",
H List Box( c1 = dt << Contingency( Y( :size ), X( :marital status ), ), c2 = dt << Contingency( Y( :size ), X( :country ), ) )
);
cs1 = c1 << Column Switcher( :marital status, {:sex, :country, :marital status} );
cs2 = c2 << Column Switcher( :country, {:sex, :country, :marital status} );
cs1 << Broadcast( Next() );
Code Explanation:
- Set default names to here.
- Open data table;
- Create new window named CS broadcast.
- Add horizontal list box with two contingency tables.
- First contingency table: Y is size, X is marital status.
- Second contingency table: Y is size, X is country.
- Add column switcher to first contingency table.
- Switcher options: marital status, sex, country.
- Add column switcher to second contingency table.
- Switcher options: country, sex, marital status.
- Broadcast next from first column switcher.
Example 4
Summary: Creates a new window with two tab pages, fitting logistic and contingency models to analyze age and weight, as well as sex, respectively.
Code:
dt = Open("data_table.jmp");
New Window( "dock close",
H Splitter Box(
Size( 600, 300 ),
tp1 = Tab Page Box(
"Logistic",
dt << Logistic(
Y( :age ),
X( :weight ),
SendToReport(
Dispatch( {}, "Whole Model Test", OutlineBox, {Close( 1 )} ),
Dispatch( {}, "Parameter Estimates", OutlineBox, {Close( 1 )} )
)
),
<<Moveable( 1 ),
<<Closeable( 1 ),
<<Icon( "Logistic" ),
<<Set Close( Function( {this}, Print( "tab closed" ) ) ),
<<Set Close Tip( "Close Logistic" )
),
tp2 = Tab Page Box(
"Contingency",
dt << Contingency(
Y( :age ),
X( :sex ),
Contingency Table,
SendToReport(
Dispatch( {}, "Contingency Table", OutlineBox, {Close( 1 )} ),
Dispatch( {}, "Tests", OutlineBox, {Close( 1 )} )
)
),
<<Moveable( 1 ),
<<Closeable( 1 ),
<<Icon( "Conting" ),
<<Set Close( Function( {this}, Print( "tab closed" ) ) ),
<<Set Close Tip( "Close Contingency" )
),
<<Dockable( 1 )
)
);
tp1 << Closeable( 0 );
Close( dt, "nosave" );
win = New Window( "Example",
Tab Box( "First Tab", Text Box( "Text One" ), "Second Tab", Button Box( "Press Two" ), "Third Tab", Number Edit Box( 3 ) )
);
win << Save Journal( "$temp/jrn1.jrn" );
Code Explanation:
- Open data table;
- Create new window "dock close".
- Add horizontal splitter box.
- Create tab page "Logistic".
- Fit logistic model with age and weight.
- Close "Whole Model Test" and "Parameter Estimates".
- Make tab moveable and closeable.
- Set icon and close function for "Logistic".
- Create tab page "Contingency".
- Fit contingency model with age and sex.
- Close "Contingency Table" and "Tests".
- Make tab moveable and closeable.
- Set icon and close function for "Contingency".
- Make window dockable.
- Disable close for "Logistic" tab.
- Close data table without saving.
- Create new window "Example".
- Add tab box with three tabs.
- Save journal to $temp/jrn1.jrn.
Example 5
Summary: Creates a dockable window with two tabs, one for logistic regression and another for contingency analysis, using JMP Scripting Language (JSL) to fit models and generate reports.
Code:
dt = Open("data_table.jmp");
New Window( "dock close",
H Splitter Box(
Size( 600, 300 ),
tp1 = Tab Page Box(
"Logistic",
dt << Logistic(
Y( :age ),
X( :weight ),
SendToReport(
Dispatch( {}, "Whole Model Test", OutlineBox, {Close( 1 )} ),
Dispatch( {}, "Parameter Estimates", OutlineBox, {Close( 1 )} )
)
),
<<Moveable( 1 ),
<<Closeable( 1 ),
<<Icon( "Logistic" ),
<<Set Close( Function( {this}, Print( "tab closed" ) ) )
),
tp2 = Tab Page Box(
"Contingency",
dt << Contingency(
Y( :age ),
X( :sex ),
Contingency Table,
SendToReport(
Dispatch( {}, "Contingency Table", OutlineBox, {Close( 1 )} ),
Dispatch( {}, "Tests", OutlineBox, {Close( 1 )} )
)
),
<<Moveable( 1 ),
<<Closeable( 1 ),
<<Icon( "Conting" ),
<<Set Close( Function( {this}, Print( "tab closed" ) ) )
),
<<Dockable( 1 )
)
);
tp1 << Icon( "$sample_images/pi.gif" );
tp1 << Icon( "Distrib" );
Close( dt, "nosave" );
New Window( "Example",
tb = Tab Box(
tp1 = Tab Page Box( "First Tab", Button Box( "Press One" ), ),
tp2 = Tab Page Box( "Second Tab", Button Box( "Press Two" ), ),
tp3 = Tab Page Box( "Third Tab", Button Box( "Press Three" ) )
)
);
tp3 << Visibility( "Collapse" );
tb << Set Selected( 2 );
tb << Move Tab( 3, 1 );
tb << Move Tab( 2, 1 );
tb << Move Tab( 1, 3 );
tb << Move Tab( 2, 3 );
tb << Set Selected( 1 );
tb << Set Selected( 2 );
tp2 << Visibility( "Collapse" );
tb << close window;
win = New Window( "Example",
Tab Box(
t1 = Tab Page Box( "alpha", Panel Box( "panel", Text Box( "text" ) ) ),
t2 = Tab Page Box( "beta", Button Box( "Press Me", Print( "Pressed." ) ) ),
)
);
t2 << Visibility( "Collapse" );
Code Explanation:
- Open data table.
- Create new dockable window.
- Add horizontal splitter box.
- Create logistic regression tab.
- Fit logistic model.
- Hide whole model test.
- Hide parameter estimates.
- Make tab movable.
- Make tab closable.
- Set tab icon.
- Define close action.
- Create contingency tab.
- Fit contingency analysis.
- Hide contingency table.
- Hide tests.
- Make tab movable.
- Make tab closable.
- Set tab icon.
- Define close action.
- Set splitter dockable.
- Change logistic tab icon.
- Change logistic tab icon again.
- Close data table without saving.
- Create new example window.
- Add tab box.
- Add first tab with button.
- Add second tab with button.
- Add third tab with button.
- Collapse third tab.
- Select second tab.
- Move third tab to first position.
- Move second tab to first position.
- Move first tab to third position.
- Move second tab to third position.
- Select first tab.
- Select second tab.
- Collapse second tab.
- Close example window.
- Create new example window.
- Add tab box.
- Add alpha tab with panel and text.
- Add beta tab with button.
- Collapse beta tab.
Contingency using Data Table
Summary: Opens a data table, stacks columns, and performs contingency analysis to examine the relationship between characteristics and importance.
Code:
// Stack Columns and Analyze
// Open data table
dt = Open("data_table.jmp");
// Stack Columns and Analyze
Data Table("data_table")
<< Stack(
columns(
:Grades, :Sports, :Looks, :Money
),
Source Label Column(
"Characteristic"
),
Stacked Data Column( "Importance" ),
Output Table( "Stacked Importance" )
);
Contingency(
Y( :Characteristic ),
X( :Importance ),
Contingency Table(
Count( 1 ),
Total %( 0 ),
Col %( 0 ),
Row %( 0 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
)
);
Code Explanation:
- Open table.
- Stack columns.
- Create stacked data table.
- Perform contingency analysis.
- Set Y variable.
- Set X variable.
- Configure contingency options.
- Disable count display.
- Disable percentage displays.
- Display results.
Contingency using Distribution
Example 1
Summary: Performs a distribution analysis with continuous and nominal variables, applying local data filters for age and recalculation on the weight column.
Code:
dt = Open("data_table.jmp");
Distribution(
Automatic Recalc( 1 ),
Continuous Distribution( Column( :weight ) ),
Nominal Distribution( Column( :age ) ),
Local Data Filter( Close Outline( 1 ), Add Filter( columns( :age ), Where( :age == {12, 13, 14} ) ) ),
);
Contingency(
Y( :age ),
X( :sex ),
Automatic Recalc( 1 ),
Contingency Table,
Local Data Filter(
Close Outline( 1 ),
Add Filter( columns( :age ), Where( :age == {12, 13, 14, 15} ), Display( :age, Size( 181, 102 ), List Display ) )
)
);
Code Explanation:
- Open data table.
- Create distribution analysis.
- Set automatic recalculation on.
- Analyze weight column continuously.
- Analyze age column nominally.
- Add local data filter for age.
- Filter age to 12, 13, 14.
- Create contingency analysis.
- Set Y as age.
- Set X as sex.
Example 2
Summary: Analyze nominal and continuous variables in a data table, creating distributions for 'sex', 'marital status', 'age', 'country', 'size', and 'type', as well as a contingency table for 'size' vs 'marital status'.
Code:
dt = Open("data_table.jmp");
obj = dt << Distribution(
Automatic Recalc( 1 ),
Nominal Distribution( Column( :sex ) ),
Nominal Distribution( Column( :marital status ) ),
Continuous Distribution( Column( :age ) ),
Nominal Distribution( Column( :country ) ),
Nominal Distribution( Column( :size ) ),
Nominal Distribution( Column( :type ) ),
);
obj = Contingency( Y( :size ), X( :marital status ) );
Code Explanation:
- Open data table;
- Create distribution object.
- Set automatic recalculation.
- Analyze "sex" as nominal.
- Analyze "marital status" as nominal.
- Analyze "age" as continuous.
- Analyze "country" as nominal.
- Analyze "size" as nominal.
- Analyze "type" as nominal.
- Create contingency table for "size" vs "marital status".
Example 3
Summary: Analyze nominal and continuous columns in a data table, including contingency tables and distribution plots, using JMP's Distribution and Column Switcher features.
Code:
dt under test = Open("data_table.jmp");
obj = dt under test << Distribution(
Automatic Recalc( 1 ),
Nominal Distribution( Column( :sex ) ),
Nominal Distribution( Column( :marital status ) ),
Continuous Distribution( Column( :age ) ),
Nominal Distribution( Column( :country ) ),
Nominal Distribution( Column( :size ) ),
Nominal Distribution( Column( :type ) ),
);
obj = Contingency( Y( :size ), X( :marital status ) );
ColumnSwitcherObject = obj << Column Switcher( :marital status, {:sex, :country, :marital status, :size, :type, :age} );
Code Explanation:
- Open data table;
- Create distribution analysis.
- Set automatic recalculation.
- Analyze nominal column "sex".
- Analyze nominal column "marital status".
- Analyze continuous column "age".
- Analyze nominal column "country".
- Analyze nominal column "size".
- Analyze nominal column "type".
- Create contingency analysis for "size" vs. "marital status".
Example 4
Summary: Analyze a data table by creating a distribution object, enabling automatic recalculation, and applying nominal and continuous distributions to various columns. It also generates a contingency table for 'size' vs 'marital status' with a column switcher.
Code:
dt under test = Open("data_table.jmp");
obj = dt under test << Distribution(
Automatic Recalc( 1 ),
Nominal Distribution( Column( :sex ) ),
Nominal Distribution( Column( :marital status ) ),
Continuous Distribution( Column( :age ) ),
Nominal Distribution( Column( :country ) ),
Nominal Distribution( Column( :size ) ),
Nominal Distribution( Column( :type ) ),
);
obj = Contingency( Y( :size ), X( :marital status ) );
ColumnSwitcherObject = obj << Column Switcher( :marital status, {:sex, :country, :marital status, :type, :age} );
Code Explanation:
- Open data table.
- Create distribution object.
- Enable automatic recalculation.
- Analyze nominal 'sex' column.
- Analyze nominal 'marital status' column.
- Analyze continuous 'age' column.
- Analyze nominal 'country' column.
- Analyze nominal 'size' column.
- Analyze nominal 'type' column.
- Create contingency table for 'size' vs 'marital status'.
- Add column switcher to contingency table.
Contingency using Graph Builder
Example 1
Summary: Creates two variability charts with nested factors using Graph Builder, displaying standard deviation charts and performing chi-square tests.
Code:
Open("data_table.jmp");
Graph Builder(
Size( 534, 448 ),
Show Control Panel( 0 ),
Variables( X( :sex ), Y( :age ) ),
Elements( Mosaic( X, Y, Legend( 4 ), Name( "Chi-square Test" )(1) ) )
);
Contingency( Y( :age ), X( :sex ), Contingency Table );
Graph Builder(
Size( 534, 448 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements( Mosaic( X, Y, Legend( 4 ), Name( "Chi-square Test" )(1) ) )
);
Code Explanation:
- Open data table;
- Launch Graph Builder.
- Set graph size.
- Hide control panel.
- Assign variables to axes.
- Add mosaic element.
- Perform chi-square test.
- Create contingency table.
- Launch another Graph Builder.
- Set new graph size.
Example 2
Summary: Creates a mosaic plot to visualize the relationship between country and size, utilizing Graph Builder and performing contingency analysis.
Code:
Open("data_table.jmp");
gb = Graph Builder(
Size( 534, 448 ),
Show Control Panel( 0 ),
Variables( X( :country ), Y( :size ) ),
Elements( Mosaic( X, Y, Legend( 4 ), Name( "Chi-square Test" )(1) ) )
);
contingency_analysis = Contingency( Y( :Size ), X( :country ), Contingency Table );
Code Explanation:
- Open data table;
- Create new Graph Builder object.
- Set window size to 534x448.
- Hide control panel.
- Assign X variable: country.
- Assign Y variable: size.
- Add Mosaic element to graph.
- Enable Chi-square test in legend.
- Perform contingency analysis on Size vs country.
- Display contingency table.
Example 3
Summary: Creates a mosaic chart with nested factors using Graph Builder, enabling chi-square test and contingency analysis.
Code:
dt = Open("data_table.jmp");
gb = Graph Builder(
Size( 534, 448 ),
Show Control Panel( 0 ),
Variables( X( :country ), Y( :size ) ),
Elements( Mosaic( X, Y, Legend( 4 ), Name( "Chi-square Test" )(1) ) )
);
contingency_analysis = Contingency( Y( :Size ), X( :country ), Contingency Table );
Code Explanation:
- Open data table;
- Create Graph Builder object.
- Set graph size.
- Hide control panel.
- Assign X and Y variables.
- Add mosaic element.
- Enable chi-square test.
- Perform contingency analysis.
- Set Y variable for analysis.
- Set X variable for analysis.
Contingency using For Each
Summary: Creates and configures contingency analyses for multiple samples, utilizing the Contingency platform in JMP.
Code:
plat_samples = ["Contingency" => {"ANOM for Proportions", "Simple Publication Mosaic"}, => {}];
dt = Open("data_table.jmp");
For Each( {sample}, plat_samples["Contingency"],
obj = dt << Contingency( Y( :Age ), X( :sex ) );
Eval( Eval Expr( obj << Apply Preset( "Sample Presets", Expr( sample ) ) ) );
obj << Set Report Title( sample );
);
Code Explanation:
- Define preset samples.
- Open data table.
- Loop through each sample.
- Create contingency analysis.
- Apply preset to analysis.
- Set report title to sample name.
- Repeat for all samples.
Contingency using Fit Group
Example 1
Summary: Creates contingency analysis for Type and Model, as well as Type and Country, with correspondence analysis, measures of association, Fisher's exact test, and Cochran Mantel Haenszel test.
Code:
dt under test = Open("data_table.jmp");
obj = Fit Group(
Contingency(
Y( :Type ),
X( :Model ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Correspondence Analysis( 1 )
),
Contingency(
Y( :Type ),
X( :Country ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Correspondence Analysis( 1 ),
Measures of Association( 1 ),
Fisher's Exact Test( 1 ),
Cochran Mantel Haenszel( :Weight )
),
<<{Arrange in Rows( 2 )},
SendToReport( Dispatch( {"Contingency Analysis of Type By Model", "Correspondence
Analysis"}, "Details", OutlineBox, {Close( 0 )} ) )
);
Code Explanation:
- Open data table.
- Create contingency analysis for Type and Model.
- Configure contingency table settings.
- Enable correspondence analysis.
- Create second contingency analysis for Type and Country.
- Configure second contingency table settings.
- Enable correspondence analysis.
- Enable measures of association.
- Enable Fisher's exact test.
- Enable Cochran Mantel Haenszel test with Weight.
Example 2
Summary: Analyze contingency tables for Type and Model, as well as Type and Country, with correspondence analysis, measures of association, and Cochran-Mantel-Haenszel test, and arranges reports in rows.
Code:
dt under test = Open("data_table.jmp");
obj = Fit Group(
Contingency(
Y( :Type ),
X( :Model ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Correspondence Analysis( 1 )
),
Contingency(
Y( :Type ),
X( :Country ),
Contingency Table(
Count( 1 ),
Total %( 1 ),
Col %( 1 ),
Row %( 1 ),
Expected( 0 ),
Deviation( 0 ),
Cell Chi Square( 0 ),
Col Cum( 0 ),
Col Cum %( 0 ),
Row Cum( 0 ),
Row Cum %( 0 )
),
Correspondence Analysis( 1 ),
Measures of Association( 1 ),
Cochran Mantel Haenszel( :Weight )
),
<<{Arrange in Rows( 2 )},
SendToReport( Dispatch( {"Contingency Analysis of Type By Model", "Correspondence Analysis"}, "Details", OutlineBox, {Close( 0 )} ) )
);
Code Explanation:
- Open data table.
- Fit contingency analysis on Type and Model.
- Configure contingency table options.
- Enable correspondence analysis.
- Fit another contingency analysis on Type and Country.
- Configure contingency table options.
- Enable correspondence analysis.
- Enable measures of association.
- Enable Cochran-Mantel-Haenszel test.
- Arrange reports in rows.
Contingency using If
Summary: Creates and configures a contingency table with automatic recalculation, utilizing JMP scripting language.
Code:
If( JMP Version() >= " 8.0.2",
dt = Open("data_table.jmp");
ct = Contingency( Y( sex ), X( age ) );
ct << Automatic Recalc( 1 );
s = ct << Get Script;
arflag = 0;
For( i = 1, i <= N Arg( s ) & !arflag, i++,
arflag = Arg( s, i ) == Expr( Automatic Recalc( 1 ) )
);
Close( dt, No Save );
);
Code Explanation:
- Check JMP version.
- Open data table;
- Create contingency table.
- Enable automatic recalculation.
- Retrieve script from table.
- Initialize flag variable.
- Loop through script arguments.
- Check for "Automatic Recalc".
- Set flag if found.
- Close table without saving.
Contingency using Select Where
Summary: Selects and analyzes a subset of data based on size criteria, generating a contingency table with relative risk calculations for sex by size.
Code:
dt = Open("data_table.jmp");
dt << Select Where( :size == "Small" | :size == "Medium" );
dtsub1 = dt << Subset( Selected Rows );
cont1 = dtsub1 << Contingency(
Y( :sex ),
X( :size ),
Contingency Table( 0 ),
Mosaic Plot( 0 ),
Tests( 0 ),
Relative Risk( 1, "Male", "Medium" ),
Risk Difference( 1 ),
Odds Ratio( 1 )
);
Code Explanation:
- Open data table;
- Select rows where size is Small or Medium.
- Create subset of selected rows.
- Run Contingency analysis.
- Set Y variable to sex.
- Set X variable to size.
- Disable Contingency Table.
- Disable Mosaic Plot.
- Disable Tests.
- Calculate Relative Risk for Male/Medium.
Contingency using Set Property
Example 1
Summary: Runs a response screening analysis to identify significant associations between 'I am working on my career' and 'Gender', generating a 2x2 contingency table, matrix, and report with relative risk, risk difference, and odds ratio calculations.
Code:
dt = Open("data_table.jmp");
:I am working on my career << Set Property( "Target Level", "Agree" );
obj1 = dt << Response Screening(
Y( :I am working on my career ),
X( :Gender ),
PValues Table on Launch( 0 ),
SendToReport(
Dispatch( {}, "Rel Risk Label", StringColBox, {Visibility( "Visible" )} ),
Dispatch( {}, "Risk Diff Label", StringColBox, {Visibility( "Visible" )} )
)
);
dt2 = obj1 << Save 2 by M;
mat1 = dt2 << get as matrix;
obj2 = dt << Contingency( Y( :I am working on my career ), X( :Gender ), Contingency Table( 0 ), Mosaic Plot( 0 ), Tests( 0 ), );
With Window Handler( obj2 << Relative Risk( 1 ), Function( {dlg}, {}, dlg[Button Box( If( Host is( "Windows" ), 1, 3 ) )] << Click ) );
obj2 << Risk Difference( 1 );
obj2 << Odds Ratio( 1 );
rpt2 = Report( obj2 );
Code Explanation:
- Open data table.
- Set target level for variable.
- Launch response screening analysis.
- Hide p-values table.
- Show relative risk label.
- Show risk difference label.
- Save 2x2 contingency table.
- Convert table to matrix.
- Launch contingency analysis.
- Calculate relative risk.
- Calculate risk difference.
- Calculate odds ratio.
- Retrieve report object.
Example 2
Summary: Runs response screening and contingency analysis to visualize the relationship between 'I am working on my career' and gender, with interactive risk difference and relative risk labels.
Code:
dt = Open("data_table.jmp");
:Gender << Set Property( "Control Level", "M" );
obj1 = dt << Response Screening(
Y( :I am working on my career ),
X( :Gender ),
PValues Table on Launch( 0 ),
SendToReport(
Dispatch( {}, "Rel Risk Label", StringColBox, {Visibility( "Visible" )} ),
Dispatch( {}, "Risk Diff Label", StringColBox, {Visibility( "Visible" )} )
)
);
dt2 = obj1 << Save 2 by M;
mat1 = dt2 << get as matrix;
obj2 = dt << Contingency( Y( :I am working on my career ), X( :Gender ), Contingency Table( 0 ), Mosaic Plot( 0 ), Tests( 0 ), );
With Window Handler( obj2 << Relative Risk( 1 ), Function( {dlg}, {}, dlg[Button Box( If( Host is( "Windows" ), 1, 3 ) )] << Click ) );
obj2 << Risk Difference( 1 );
obj2 << Odds Ratio( 1 );
rpt2 = Report( obj2 );
Code Explanation:
- Open data table.
- Set gender control level.
- Perform response screening.
- Hide P-values table.
- Show relative risk label.
- Show risk difference label.
- Save contingency table.
- Convert table to matrix.
- Create contingency analysis.
- Calculate relative risk.
Example 3
Summary: Runs a response screening analysis to identify significant relationships between 'I am working on my career' and 'Gender', with the option to save the 2x2 contingency table and visualize relative risk, risk difference, and odds ratio.
Code:
dt = Open("data_table.jmp");
:I am working on my career << Set Property( "Target Level", "Agree" );
:Gender << Set Property( "Control Level", "M" );
obj1 = dt << Response Screening(
Y( :I am working on my career ),
X( :Gender ),
PValues Table on Launch( 0 ),
SendToReport(
Dispatch( {}, "Rel Risk Label", StringColBox, {Visibility( "Visible" )} ),
Dispatch( {}, "Risk Diff Label", StringColBox, {Visibility( "Visible" )} )
)
);
dt2 = obj1 << Save 2 by M;
mat1 = dt2 << get as matrix;
obj2 = dt << Contingency(
Y( :I am working on my career ),
X( :Gender ),
Contingency Table( 0 ),
Mosaic Plot( 0 ),
Tests( 0 ),
Relative Risk( 1 ),
Risk Difference( 1 ),
Odds Ratio( 1 )
);
rpt2 = Report( obj2 );
Code Explanation:
- Open data table.
- Set target level for career question.
- Set control level for gender.
- Perform response screening analysis.
- Hide p-values table.
- Show relative risk label.
- Show risk difference label.
- Save 2x2 contingency table.
- Convert table to matrix.
- Perform contingency analysis.
Contingency using Expr
Summary: Creates and analyzes contingency tables for various categorical variables, including sex, marital status, country, and size, using Fisher's Exact Test and Cochran Armitage Trend Test.
Code:
car = Open("data_table.jmp");
fet1 = Expr(
ct << Fisher's Exact Test( 1 );
ct << close window;
Delete Symbols( ct, exout );
);
fet2 = Expr(
ct << Fisher's Exact Test( 1 );
If( isPro, ct << Tests( 0 ) );
ct << Tests( 1 );
ct << Tests( 0 );
ct << close window;
Delete Symbols( ct, exout, scr );
);
ct = Contingency( Y( :sex ), X( :marital status ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 1 ) );
ct = Contingency( Y( :sex ), X( :marital status ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 0 ) );
ct = Contingency( Y( :sex ), X( :country ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 1 ) );
ct = Contingency( Y( :sex ), X( :country ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 0 ) );
ct = Contingency( Y( :size ), X( :sex ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 1 ) );
ct = Contingency( Y( :size ), X( :sex ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 0 ) );
ct = Contingency( Y( :country ), X( :type ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 1 ) );
ct = Contingency( Y( :country ), X( :type ), Mosaic Plot( 0 ), Contingency Table( 0 ), Tests( 0 ) );
SAS_ZStat = -0.5024;
SAS_ZStatExact = 0.3302;
ct = Contingency( Y( :sex ), X( :country ), Mosaic Plot( 0 ), Contingency Table( 0 ) );
ct << Exact Cochran Armitage Trend Test( 1 );
rpt = Report( ct );
asymz = (rpt[Outline Box( "Cochran Armitage Trend Test" )][Number Col Box( 1 )] << get)[1];
exactz = (rpt[Outline Box( "Cochran Armitage Trend Test" )][Number Col Box( 4 )] << get)[1];
isPro = 1;
If( isPro,
ct << Cochran Armitage Trend Test( 0 )
);
ct << close window;
Delete Symbols( ct, scr );
Code Explanation:
- Open data table;
- Define
fet1expression. - Define
fet2expression. - Create contingency table for sex vs marital status.
- Create contingency table for sex vs marital status without tests.
- Create contingency table for sex vs country.
- Create contingency table for sex vs country without tests.
- Create contingency table for size vs sex.
- Create contingency table for size vs sex without tests.
- Create contingency table for country vs type.