Description Usage Arguments Details
This function handles the process of pushing tabular versions of rpart rules to an RODBC connection. The entire process of generation and writing is completed with a single call, with all necessary subcalls handled within this function.
1 | rpart.rules.push(object, connection, rulePrefix = NULL, tablePrefix = NULL)
|
object |
an rpart object |
connection |
and open RODBC connection |
rulePrefix |
A character string to prepend to each rule name to allow for multiple rule sets |
tablePrefix |
A character string to prepend to each table name to allow for multiple rule sets |
Once the tables have been pushed to the database, unpivoted source data can be processed using the rpart model with SQL code similar to the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | WITH SOURCE AS
(
SELECT
ID,
TYPE,
VALUE
FROM DATA
UNPIVOT
(
VALUE FOR TYPE IN (FIELD1, FIELD2, FIELD3)
)UNPVT
),
MATCHES AS
(
SELECT
ID
,Subrule
,Variable
,SR.Value
,Less
,Greater
FROM
SOURCE S
LEFT JOIN SUBRULES SR
ON
TYPE = VARIABLE
AND (
S.value = SR.value
OR S.value < SR.Less
OR S.value > SR.Greater
)
),
MATCHED_SUBRULES
AS (
SELECT
Subrule
,ID
FROM
MATCHES M
GROUP BY
Subrule
,ID
),
MATCHED_RULES
AS (
SELECT
R.[Rule]
,MS.*
FROM
RULES AS R
LEFT JOIN MATCHED_SUBRULES MS
ON R.SUBRULE=MS.SUBRULE AND Leaf='TRUE'
)
,
COUNTS AS
(
SELECT
[RULE]
,ID
,MATCH_COUNT=COUNT(DISTINCT SUBRULE)
,NEEDED_COUNT=(SELECT COUNT(DISTINCT SUBRULE) FROM RULES R WHERE R.[RULE]=MR.[RULE])
FROM
MATCHED_RULES MR
GROUP BY
[RULE]
,ID
)
SELECT
RULE
,ID
FROM COUNTS
WHERE
MATCH_COUNT=NEEDED_COUNT
|
The frame is also passed to the database which allows extracting the estimates generated by the rpart model.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.