cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Need some help implementing multirule QC

arnair81
11-Garnet

Need some help implementing multirule QC

Hi,

     I need a little help in implementing westgard (multirule QC) rules. There are 2 particular rules that I need some programming help with.  

1. The 2 of 3_2s rule: Here I need to show that there is a violation if 2 of the 3 consecutive data points exceed a certain control limit (I don't care about the limit right now. I need to get the program going).

2.The 7T rule: In this case I need to show that there is a violation if 7 consecutive values trend in a particular direction.

 

I am attaching pics for the 2 rules. I am also uploading a demo worksheet. 

Thanks in advance.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:arnair81)

So I guess I had interpreted the rules correct.

1. rule: Only max. 1 point of the three is allowed to be outside the limits

2. rule: I treat the unlikely event of two consecutive identical data points as being the same trend as the rest, so 1-2-2-3-4-4-4 would mean rule violation as all 7 are considered ascending.

 

Yes, the file is in Prime 5 format and silly as PTC is they do not provide any means to save it in P4 format.

If its enough to output the first set of data which violates the rule all you would have to do is to change the output from "return "rule ... VIOLATION" " to return the point set which violates the rule.

See attached file in Prime 4 format.

If you would need all positions violating the rule it would be more work to do.

Especially because in case of  0-3-4-5-3-2-4-5-0.5-0 and limits +-1 you probably would like to see a single entry [0 3 4 5 3 2 4 5 0.5] which violates the first rule and not [0 3 4], [3 4 5], [4 5 3], [5 3 2], [2 4 5], [4 5 0.5], though every of these set of 3 violates the rule.

View solution in original post

13 REPLIES 13
Werner_E
25-Diamond I
(To:arnair81)

Do you need to know the position of the data points violating those rules or are you just looking for a function with the data as argument and the return value is 0 or 1, indicating violation in at least one position or no violation at all?

 

Concerning the 2of3 rule: Is it also violated if one of the three data values is higher than the upper limit and another one is lower than the lower limit?

In other words, does the rule mean that at least 2 data values of 3 consecutive must be within the limits?

 

7T rule:

I guess that if two or more values are equal, the rule might be violated anyway?

Data: 1-2-3-3-3-4-5 means that all have the same trend and the rule is violated, right?

4-4-4-4-4-4-4 means rule violated?

The question is: must it be just monotone or must it be strictly monotone for the rule to be violated?

 

Werner_E
25-Diamond I
(To:Werner_E)

Here are the functions for my interpretation of your rules.

You may adopt them to your needs:

B.png

Thanks Werner. I am not able to open your file in prime 4. Are you using a newer version?

 

I want to determine the values causing the rule violation and then print it along with the corresponding row numbers.

To answer some of your questions

 

Concerning the 2of3 rule: Is it also violated if one of the three data values is higher than the upper limit and another one is lower than the lower limit?  From what I understand (I am pretty new to it as well), at least 2 of the 3 data points must be over mean +/- 2 standard deviation while the 3rd point must be within it.  

 

 

7T rule:

I guess that if two or more values are equal, the rule might be violated anyway?

Data: 1-2-3-3-3-4-5 means that all have the same trend and the rule is violated, right?

4-4-4-4-4-4-4 means rule violated? Chance of 2 data points having the exact same value is next to none for my data set. If there is a trend shift either up or down from 7 consecutive points, then the program needs to show the points causing it as well as the row numbers. Check the attached image for trend shift although I am not sure of finding 7 consecutive data points rising together.

 

Thank you once again and let me know if you need more clarification.

 

 

Werner_E
25-Diamond I
(To:arnair81)

So I guess I had interpreted the rules correct.

1. rule: Only max. 1 point of the three is allowed to be outside the limits

2. rule: I treat the unlikely event of two consecutive identical data points as being the same trend as the rest, so 1-2-2-3-4-4-4 would mean rule violation as all 7 are considered ascending.

 

Yes, the file is in Prime 5 format and silly as PTC is they do not provide any means to save it in P4 format.

If its enough to output the first set of data which violates the rule all you would have to do is to change the output from "return "rule ... VIOLATION" " to return the point set which violates the rule.

See attached file in Prime 4 format.

If you would need all positions violating the rule it would be more work to do.

Especially because in case of  0-3-4-5-3-2-4-5-0.5-0 and limits +-1 you probably would like to see a single entry [0 3 4 5 3 2 4 5 0.5] which violates the first rule and not [0 3 4], [3 4 5], [4 5 3], [5 3 2], [2 4 5], [4 5 0.5], though every of these set of 3 violates the rule.

Thanks Werner. I am able to open it now.

 

I am slightly confused by the statement below.

 

Only max. 1 point of the three is allowed to be outside the limits.  Consider the upper control limit to be mean+2 std deviation. If 2 of the data points are outside of this control limit and 1 point lies within mean and upper control limit, then it is a 2 of 3_2s violation. Similar condition exists if 2 points are below mean- 2std deviation and 1 point lies between mean and control limit.

 

So the program that you have written considers a rule violation if only 1 value goes beyond the upper control limit while the other 2 values lie between mean and upper limit? I am playing with it right now. I am observing that no matter what the limits are (changed it to [6 4]), it returns the same values [1 1 3]. 

 

The 7T program appears to be spot on. Thanks a lot Werner.

 

Werner_E
25-Diamond I
(To:arnair81)

>  I am observing that no matter what the limits are (changed it to [6 4]), it returns the same values [1 1 3]. 

Sure! Limit [6 4] means that valid are only values from 4 to 6. 1 and 3 are outside and so all three values are outside. This means that the rule is violated as there must at least two data values of three be inside the given interval. Change the limits to [5 1] for example and you will see a difference. Now 5-6-7 is the first triple where two values ( 6 and 7) are outside the given interval.

Thanks Werner. Now I get it. 

Hi Werner,

                 I just had a discussion about 2 of 3_2s rule. It requires all 3 points to lie on one side of the mean. That is 2 values beyond mean+2 std deviation and 1 value between mean and mean+ 2std deviation. (Or 2 values below mean- 2 std deviation and 1 value between mean and mean- 2 std deviation.) The program written now takes 1 value between mean+2std deviation (upper limit) and mean- 2std deviation (lower limit) and 2 values outside (1 could be greater than mean+ 2 std deviation while the other could be below mean- 2 std deviation). Even if I change the lower limit to mean, it  still takes 1 value below it and another above the upper limit.  Do you know any easy way to fix this. Sorry for the mess.

 

Thanks.

Werner_E
25-Diamond I
(To:arnair81)

> It requires all 3 points to lie on one side of the mean.

What, if one point lies exactly on the mean (even if not likely we have to deal with that case) and the other two outside on the same side?

 

What if a value is exactly mean+2*stdev? Is it considered above or not?

Its a matter of writing > or >= in the program.

 

> and 1 value between mean and mean+ 2std deviation. 

? And if all three values are above mean+2 stdev ?

So far I assumed the rule to be violated in that case

 

Werner_E
25-Diamond I
(To:Werner_E)

Here's a quick hack.

I made some assumptions and change the input parameters of the function

B.png

 

What, if one point lies exactly on the mean (even if not likely we have to deal with that case) and the other two outside on the same side? If one lies on the mean and the other 2 points lie outside mean +2 std dev on the same side, we can consider it as rule violation.

 

What if a value is exactly mean+2*stdev? Is it considered above or not?

If it is exactly same, then it can be considered to be above.

 

> and 1 value between mean and mean+ 2std deviation. 

? And if all three values are above mean+2 stdev ?

So far I assumed the rule to be violated in that case   If all three values are above or below mean +/- 2 std dev, then it is a violation of westgard rules but not 2 of 3_2s rule. For this particular rule to be violated, 2 should be beyond the control limits and 1 value must be between mean and the control limit on the same side. The program does that under certain conditions (positive bias) but under negative bias conditions, the program just takes 3 values below the lower control limit. I tried playing with it, but it is not changing anything. I have attached the file (last page). Thanks for the help.

 

 

Never mind. I think I got it. The last if statement needs to be modified so that cnt should be between 4 and 6, then it solves the problem. Thanks Werner.

Werner_E
25-Diamond I
(To:arnair81)


@arnair81 wrote:

Never mind. I think I got it. The last if statement needs to be modified so that cnt should be between 4 and 6, then it solves the problem. Thanks Werner.


Correct. I thought the rule means at least 2 out of 3 are outside and not exactly 2.

So the last if statement should read

if |cnt|=5 ...

I guess you can live with the fact that the program assumes a value which equals the mean to be neither above or below and so no violation is alarmed.

 

Announcements

Top Tags