Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL_Statistical_Functions Notebook #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SQL_Statistical_Functions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"paragraphs":[{"text":"%md\n## These SQL statistical functions examples show several use cases of descriptive and comparative statistics being performed inside the Oracle Database.","user":"CHBERGER","dateUpdated":"2017-09-03T21:43:43+0000","config":{"colWidth":8,"editorMode":"ace/mode/markdown","graph":{"mode":"table","optionOpen":false,"keys":[],"values":[],"scatter":{},"groups":[],"height":85.6667},"enabled":true,"title":false,"editorHide":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1464792666489_-1927519105","id":"20160601-105106_98198174","result":{"code":"SUCCESS","type":"HTML","msg":"<h2>These SQL statistical functions examples show several use cases of descriptive and comparative statistics being performed inside the Oracle Database.</h2>\n"},"dateCreated":"2017-09-01T14:54:21+0000","dateStarted":"2017-09-03T21:43:41+0000","dateFinished":"2017-09-03T21:43:41+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:107"},{"text":"%md\n\n![tiny arrow](http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/2773732.jpg \"tiny arrow\")\n","user":"CHBERGER","dateUpdated":"2017-09-03T21:42:57+0000","config":{"colWidth":4,"graph":{"mode":"table","height":120.667,"optionOpen":false,"keys":[],"values":[],"groups":[],"scatter":{}},"enabled":true,"editorMode":"ace/mode/markdown","editorHide":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504474834014_-1561916932","id":"20170903-214034_982857293","result":{"code":"SUCCESS","type":"HTML","msg":"<p><img src=\"http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/2773732.jpg\" alt=\"tiny arrow\" title=\"tiny arrow\" /></p>\n"},"dateCreated":"2017-09-03T21:40:34+0000","dateStarted":"2017-09-03T21:41:40+0000","dateFinished":"2017-09-03T21:41:40+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:108"},{"text":"%md\n### For more information on this, check the Oracle 12.2 Documentation \n#### http://docs.oracle.com/database/121/SQLRF/functions191.htm#SQLRF06323","user":"CHBERGER","dateUpdated":"2017-09-01T15:07:31+0000","config":{"colWidth":12,"graph":{"mode":"table","height":300,"optionOpen":false,"keys":[],"values":[],"groups":[],"scatter":{}},"enabled":true,"editorMode":"ace/mode/markdown","editorHide":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504277805505_-661425658","id":"20170901-145645_781975700","result":{"code":"SUCCESS","type":"HTML","msg":"<h3>For more information on this, check the Oracle 12.2 Documentation</h3>\n<h4>http://docs.oracle.com/database/121/SQLRF/functions191.htm#SQLRF06323</h4>\n"},"dateCreated":"2017-09-01T14:56:45+0000","dateStarted":"2017-09-01T15:03:28+0000","dateFinished":"2017-09-01T15:03:28+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:109"},{"title":"Display the Statistical Mode","text":"%sql\nSELECT STATS_MODE(MARITAL_STATUS) from CUST_INSUR_LTV;","user":"CHBERGER","dateUpdated":"2017-09-01T15:09:20+0000","config":{"colWidth":12,"graph":{"mode":"table","height":84.6667,"optionOpen":false,"keys":[{"name":"STATS_MODE(MARITAL_STATUS)","index":0,"aggr":"sum"}],"values":[],"groups":[],"scatter":{"xAxis":{"name":"STATS_MODE(MARITAL_STATUS)","index":0,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504278192785_2114736870","id":"20170901-150312_843346827","result":{"code":"SUCCESS","type":"TABLE","msg":"STATS_MODE(MARITAL_STATUS)\nSINGLE\n","comment":""},"dateCreated":"2017-09-01T15:03:12+0000","dateStarted":"2017-09-01T15:08:34+0000","dateFinished":"2017-09-01T15:08:34+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:110"},{"title":"Display Median MORTGAGE_AMOUNT","text":"%sql\nSELECT MEDIAN(MORTGAGE_AMOUNT) from CUST_INSUR_LTV;\n","user":"CHBERGER","dateUpdated":"2017-09-01T15:14:24+0000","config":{"colWidth":12,"graph":{"mode":"table","height":89.6667,"optionOpen":true,"keys":[{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":0,"aggr":"sum"}],"values":[{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":0,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":0,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504278496602_320063852","id":"20170901-150816_1406828413","result":{"code":"SUCCESS","type":"TABLE","msg":"MEDIAN(MORTGAGE_AMOUNT)\n1100\n","comment":""},"dateCreated":"2017-09-01T15:08:16+0000","dateStarted":"2017-09-01T15:14:24+0000","dateFinished":"2017-09-01T15:14:24+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:111"},{"title":"Display Median MORTGAGE_AMOUNT for each MARITAL_STATUS","text":"%sql\nSELECT MARITAL_STATUS, MEDIAN(MORTGAGE_AMOUNT) from CUST_INSUR_LTV GROUP BY MARITAL_STATUS;\n","user":"CHBERGER","dateUpdated":"2017-09-01T15:14:12+0000","config":{"colWidth":12,"graph":{"mode":"table","height":189.667,"optionOpen":false,"keys":[{"name":"MARITAL_STATUS","index":0,"aggr":"sum"}],"values":[{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"MARITAL_STATUS","index":0,"aggr":"sum"},"yAxis":{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504278581744_-234435934","id":"20170901-150941_1156635930","result":{"code":"SUCCESS","type":"TABLE","msg":"MARITAL_STATUS\tMEDIAN(MORTGAGE_AMOUNT)\nMARRIED\t1200\nWIDOWED\t6000\nDIVORCED\t2994\nOTHER\t15500\nSINGLE\t0\n","comment":""},"dateCreated":"2017-09-01T15:09:41+0000","dateStarted":"2017-09-01T15:11:04+0000","dateFinished":"2017-09-01T15:11:04+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:112"},{"title":"Display Median MORTGAGE_AMOUNT for each MARITAL_STATUS in Ascending Order","text":"%sql\nSELECT MARITAL_STATUS, MEDIAN(MORTGAGE_AMOUNT) from CUST_INSUR_LTV GROUP BY MARITAL_STATUS ORDER BY MEDIAN(MORTGAGE_AMOUNT) ASC;","user":"CHBERGER","dateUpdated":"2017-09-01T15:13:58+0000","config":{"colWidth":12,"graph":{"mode":"table","height":179.667,"optionOpen":false,"keys":[{"name":"MARITAL_STATUS","index":0,"aggr":"sum"}],"values":[{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"MARITAL_STATUS","index":0,"aggr":"sum"},"yAxis":{"name":"MEDIAN(MORTGAGE_AMOUNT)","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504278664138_1303728872","id":"20170901-151104_2045753922","result":{"code":"SUCCESS","type":"TABLE","msg":"MARITAL_STATUS\tMEDIAN(MORTGAGE_AMOUNT)\nSINGLE\t0\nMARRIED\t1200\nDIVORCED\t2994\nWIDOWED\t6000\nOTHER\t15500\n","comment":""},"dateCreated":"2017-09-01T15:11:04+0000","dateStarted":"2017-09-01T15:13:41+0000","dateFinished":"2017-09-01T15:13:41+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:113"},{"title":"ANOVA Analysis of Variance SQL function using CUSTOMERS and SALES tables","text":"%sql\n-- Compares AMOUNT_SOLD by CUST_GENDER using ANOVA {see http://docs.oracle.com/database/121/SQLRF/functions190.htm#SQLRF06322)\nSELECT cust_gender, \n STATS_ONE_WAY_ANOVA(cust_income_level, amount_sold, 'F_RATIO') f_ratio, \n STATS_ONE_WAY_ANOVA(cust_income_level, amount_sold, 'SIG') p_value \n FROM customers c, sales s \n WHERE c.cust_id = s.cust_id \n GROUP BY cust_gender \n ORDER BY cust_gender","user":"CHBERGER","dateUpdated":"2017-09-03T22:20:36+0000","config":{"colWidth":12,"graph":{"mode":"table","height":129.667,"optionOpen":false,"keys":[{"name":"CUST_GENDER","index":0,"aggr":"sum"}],"values":[{"name":"F_RATIO","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"CUST_GENDER","index":0,"aggr":"sum"},"yAxis":{"name":"F_RATIO","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504476890454_-761476708","id":"20170903-221450_790144396","result":{"code":"SUCCESS","type":"TABLE","msg":"CUST_GENDER\tF_RATIO\tP_VALUE\nF\t5.59536943380348098522161131866950331161E00\t0.0000000047839510702026533\nM\t9.28650009884073109484293273601018786536E00\t0.000000000000000067139449119250277\n","comment":""},"dateCreated":"2017-09-03T22:14:50+0000","dateStarted":"2017-09-03T22:20:36+0000","dateFinished":"2017-09-03T22:20:36+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:114"},{"title":"Compare the Average Amount Purchased by Men vs. Sold to Women using a SQL Statistical t-test","text":"%sql\n-- Uses SQL t-test function. (See http://docs.oracle.com/database/121/SQLRF/functions191.htm#SQLRF06323)\n-- Statistical SQL functions for performing t-test in-Database using the SH.Sales and SH.Customers tables. The t-test measures the significance of a difference of means. \n-- You can use it to compare the means of two groups or the means of one group with a constant. A t-test is any statistical hypothesis test in which the test statistic\n-- follows a Student's t-distribution under the null hypothesis. It can be used to determine if two sets of data are significantly different from each other, and is most\n-- commonly applied when the test statistic would follow a normal distribution if the value of a scaling term in the test statistic were known. When the scaling term is\n-- unknown and is replaced by an estimate based on the data, the test statistic (under certain conditions) follows a Student's t distribution. \n-- See https://en.wikipedia.org/wiki/Student%27s_t-test\n\nSELECT substr(cust_income_level,1,22) income_level, \n\tavg(decode(cust_gender,'M',amount_sold,null)) sold_to_men, \n\tavg(decode(cust_gender,'F',amount_sold,null)) sold_to_women, \n\tstats_t_test_indep(cust_gender, amount_sold, 'STATISTIC','F') t_observed, \n\tstats_t_test_indep(cust_gender, amount_sold) two_sided_p_value \nFROM customers c, sales s \nWHERE c.cust_id=s.cust_id \nGROUP BY rollup(cust_income_level) \n\tORDER BY 1","user":"CHBERGER","dateUpdated":"2017-09-03T22:23:50+0000","config":{"colWidth":12,"graph":{"mode":"table","height":300,"optionOpen":false,"keys":[{"name":"INCOME_LEVEL","index":0,"aggr":"sum"}],"values":[{"name":"SOLD_TO_MEN","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"INCOME_LEVEL","index":0,"aggr":"sum"},"yAxis":{"name":"SOLD_TO_MEN","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504277741769_-1428892445","id":"20170901-145541_1558980534","result":{"code":"SUCCESS","type":"TABLE","msg":"INCOME_LEVEL\tSOLD_TO_MEN\tSOLD_TO_WOMEN\tT_OBSERVED\tTWO_SIDED_P_VALUE\nA: Below 30,000\t1.05283489772952935725160521612497517707E02\t9.94281446665347318424698199089649713042E01\t-1.9880628862965003453000499545849720696E00\t0.046811481623777469\nB: 30,000 - 49,999\t1.02596509506751171121521080187379443373E02\t1.09829641827200369131387703310647133464E02\t3.04330875305933768828356081806506107293E00\t0.0023410534279906534\nC: 50,000 - 69,999\t1.05627588073092435591406700139929212281E02\t1.1012793101212474875186409907281333074E02\t2.36148671478380608770034427066569893976E00\t0.018204221087140492\nD: 70,000 - 89,999\t1.06630299489770479815187222656185078695E02\t1.10472869932602353887938839150990845991E02\t2.28496442938685864201338188738729328899E00\t0.022316997323373052\nE: 90,000 - 109,999\t1.03396741493733422882966976675356016711E02\t1.01610416258370080026130981544994283848E02\t-1.254457732177727380925691399643432194E00\t0.20967782263168744\nF: 110,000 - 129,999\t1.0676475962059620596205962059620596206E02\t1.05981311948214257102113409495121052379E02\t-6.0444998485409042286883077773557597584E-01\t0.54554530367779175\nG: 130,000 - 149,999\t1.0887753218106477177834848508720792828E02\t1.07313769857029388403494837172359015091E02\t-8.5298244925517117948924536808532181523E-01\t0.3936712177482169\nH: 150,000 - 169,999\t1.10987257925271082257061951792250846053E02\t1.07152191179957322374140520034774361811E02\t-1.9062363114356126707468714606477246534E00\t0.056622982960629141\nI: 170,000 - 189,999\t1.02808237970970733495805206288955507149E02\t1.07435560141216249813534881408184575605E02\t2.18477851179480576503992586978513950582E00\t0.028908565891614835\nJ: 190,000 - 249,999\t1.08040563837250087688530340231497720098E02\t1.1534335602976274041836304927699003229E02\t2.58313424607376597238444856321960839286E00\t0.0097945161125223348\nK: 250,000 - 299,999\t1.12377992926083568131406989988609795576E02\t1.08196097330051126680552925582276084075E02\t-1.4107870697666013781348428260460718022E00\t0.15831697281922252\nL: 300,000 and above\t1.20970234575835475578406169665809768638E02\t1.12216342139833600934170194132243468107E02\t-2.0642867829020208870054218880712467782E00\t0.039003861535551458\n\t1.07121844741235392320534223706176961603E02\t1.13804409820585457979225684608120868744E02\t6.86144393091179472374879840908558521905E-01\t0.49267005889819826\n\t1.06663769158722925561162462607385535301E02\t1.07276385820941568458073671870179552045E02\t1.0801349917941618400152893692788042028E00\t0.28008235736076836\n","comment":""},"dateCreated":"2017-09-01T14:55:41+0000","dateStarted":"2017-09-03T22:22:53+0000","dateFinished":"2017-09-03T22:22:54+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:115"},{"title":"Run SQL Correlations Analysis Query to Determine Whether there is a Correlation between the AGE and WEIGHT of People (using LYMPHOMA data and Spearmans correlation)","text":"%sql\nselect CORR_S(AGE, WEIGHT) \tcoefficient,\n\tCORR_S(AGE, WEIGHT, \t'TWO_SIDED_SIG')\n\tp_value, substr(TREATMENT_PLAN, 1,15) as TREATMENT_PLAN\nfrom LYMPHOMA\nGROUP BY TREATMENT_PLAN; ","user":"CHBERGER","dateUpdated":"2017-09-03T22:04:21+0000","config":{"colWidth":12,"graph":{"mode":"table","height":144.667,"optionOpen":false,"keys":[{"name":"COEFFICIENT","index":0,"aggr":"sum"}],"values":[{"name":"P_VALUE","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"COEFFICIENT","index":0,"aggr":"sum"},"yAxis":{"name":"P_VALUE","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","lineNumbers":false,"title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504278679152_1146598079","id":"20170901-151119_520932097","result":{"code":"SUCCESS","type":"TABLE","msg":"COEFFICIENT\tP_VALUE\tTREATMENT_PLAN\n0.07293916230870659\t0.43050688502878476\tChemo&Radiation\n-0.026675413715028004\t0.45061319035988978\tChemo_only\n0.026348195180743206\t0.7448529244893255\tExperimental\n-0.097932517509351086\t0.0030225140232899008\tRadiation\n","comment":""},"dateCreated":"2017-09-01T15:11:19+0000","dateStarted":"2017-09-03T22:03:51+0000","dateFinished":"2017-09-03T22:03:51+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:116"},{"title":"Run SQL Cross Tabulations Query to Analyze the Strength of the Association Between TREATMENT_PLAN and GENDER Grouped By LYMPH_TYPE using a cross tabulation","text":"%sql\nSELECT LYMPH_TYPE,\nstats_crosstab(GENDER, TREATMENT_PLAN,\n\t'CHISQ_OBS') chi_squared,\n\tstats_crosstab(GENDER, TREATMENT_PLAN,\n\t'CHISQ_SIG') p_value,\n\tstats_crosstab(GENDER, TREATMENT_PLAN,\n\t'PHI_COEFFICIENT') phi_coefficient\nFROM LYMPHOMA\n GROUP BY LYMPH_TYPE ORDER BY 1;\n","user":"CHBERGER","dateUpdated":"2017-09-03T22:06:07+0000","config":{"colWidth":12,"graph":{"mode":"table","height":119.667,"optionOpen":false,"keys":[{"name":"LYMPH_TYPE","index":0,"aggr":"sum"}],"values":[{"name":"CHI_SQUARED","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"LYMPH_TYPE","index":0,"aggr":"sum"},"yAxis":{"name":"CHI_SQUARED","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504475108588_-888238577","id":"20170903-214508_133997196","result":{"code":"SUCCESS","type":"TABLE","msg":"LYMPH_TYPE\tCHI_SQUARED\tP_VALUE\tPHI_COEFFICIENT\nAgressive\t1.14739673290923376773313299747326009652E01\t0.0094205604338903261\t2.36006081552095717905499991773405774376E-01\nIndolent\t6.14325390371723980735077936142008696551E01\t0.00000000000029049412073596857\t1.85359767234911405505035561867026615351E-01\n","comment":""},"dateCreated":"2017-09-03T21:45:08+0000","dateStarted":"2017-09-03T22:06:07+0000","dateFinished":"2017-09-03T22:06:07+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:117"},{"title":"Run 1-Way ANOV SQL Query Query to Compare the Average SIZE_REDUCTION within Different TREATMENT_PLANS Grouped By LYMPH_TYPE","text":"%sql\nSELECT LYMPH_TYPE,\n \tstats_one_way_anova(TREATMENT_PLAN,\n \tSIZE_REDUCTION,'F_RATIO') f_ratio,\n \tstats_one_way_anova(TREATMENT_PLAN, \n \tSIZE_REDUCTION,'SIG') p_value\n \tFROM LYMPHOMA \n\tGROUP BY LYMPH_TYPE ORDER BY 1;\n","user":"CHBERGER","dateUpdated":"2017-09-08T18:19:50+0000","config":{"colWidth":12,"graph":{"mode":"table","height":124.333,"optionOpen":false,"keys":[{"name":"LYMPH_TYPE","index":0,"aggr":"sum"}],"values":[{"name":"F_RATIO","index":1,"aggr":"sum"}],"groups":[],"scatter":{"xAxis":{"name":"LYMPH_TYPE","index":0,"aggr":"sum"},"yAxis":{"name":"F_RATIO","index":1,"aggr":"sum"}}},"enabled":true,"editorMode":"ace/mode/osql","title":true},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504476276725_353636162","id":"20170903-220436_1956458637","result":{"code":"SUCCESS","type":"TABLE","msg":"LYMPH_TYPE\tF_RATIO\tP_VALUE\nAgressive\t1.45110113954054249677479322827316658203E00\t0.22914102847034823\nIndolent\t1.4899720774978706508716099380880518446E01\t0.0000000013950913067140734\n","comment":""},"dateCreated":"2017-09-03T22:04:36+0000","dateStarted":"2017-09-03T22:08:35+0000","dateFinished":"2017-09-03T22:08:35+0000","status":"FINISHED","progressUpdateIntervalMs":500,"commited":true,"$$hashKey":"object:118"},{"text":"","dateUpdated":"2017-09-03T22:07:28+0000","config":{"colWidth":12,"graph":{"mode":"table","height":300,"optionOpen":false,"keys":[],"values":[],"groups":[],"scatter":{}},"enabled":true,"editorMode":"ace/mode/scala"},"settings":{"params":{},"forms":{}},"jobName":"paragraph_1504476438266_787430419","id":"20170903-220718_177703979","dateCreated":"2017-09-03T22:07:18+0000","status":"READY","progressUpdateIntervalMs":500,"commited":false,"$$hashKey":"object:119"}],"name":"SQL Statistical Functions Examples","id":"341","angularObjects":{"ORABFFB941D7E:shared_process":[],"ORA2D5A730F41:shared_process":[],"ORA34E3A55861:shared_process":[],"MDW38312251B1:shared_process":[],"ANG38312251B1:shared_process":[]},"config":{"looknfeel":"default"},"info":{}}