Merck / Merck/SPC_Package

Question about Rules 5 and 6

Open
#3 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Thank you for coding Nelson's rules into R. I have been learning Nelson's rules, and for my own understanding, I have been studying your code. I wonder about a line within Rules 5 and 6.

I have a question about the line from Rule5().

ifelse(((sum(temp == 1) >= minNPoints) &  temp[length(temp)] == 1) |
 ((sum(temp == -1) >= minNPoints) & temp[length(temp)] == -1), 
1, 
0)

Looking at the first part of the condition statement, I don't understand the value of temp[length(temp)] == 1) as this seems repetitive from sum(temp == 1) >= minNPoints. It seems that equality will always be TRUE if the inequality is TRUE, and if the inequality is FALSE, the equality will always be FALSE. Is there a case that the inequality would be FALSE but the equality would be TRUE?

Thanks.

For your (and other viewers') reference, here is the complete function for Rule5.

Rspc::Rule5
function (x, zoneB, minNPoints = 2, nPoints = 3, ...) 
{
    xOriginal = x
    x = na.omit(x)
    lenorig = length(xOriginal)
    len = length(x)
    if (len < nPoints) {
        return(rep(0, times = lenorig))
    }
    upper <- zoneB["2"]
    lower <- zoneB["-2"]
    xZoned <- ifelse(x > upper, 1, ifelse(x < lower, -1, 0))
    violation <- rep(0, times = len)
    if (all(xZoned[1:minNPoints] == 1) | all(xZoned[1:minNPoints] == 
        -1)) {
        violation[minNPoints] = 1
    }
    for (i in nPoints:len) {
        temp <- xZoned[(i - nPoints + 1):i]
        violation[i] = ifelse(((sum(temp == 1) >= minNPoints) & 
            temp[length(temp)] == 1) | ((sum(temp == -1) >= minNPoints) & 
            temp[length(temp)] == -1), 1, 0)
    }
    violation <- replace(xOriginal, !is.na(xOriginal), violation)
    violation[is.na(violation)] <- 0
    return(violation)
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rspc::Rule5 entry point and inspect the temp window and condition shown in the issue. Determine whether the final-value check is intentional, then document the reasoning or clarify the implementation so the question is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.