# Non-inferiority testing.

#### akooha

##### New Member
Hello all!

I am struggling to understand a non-inferiority analysis described in a paper by Meijer et al. 2009 for HPV-testing validation guidelines. The paper describes the test to be used as:

I've tried writing a function in R for this test, but the numbers I get are wildly off; maybe someone here can help me to get this right?

For the sensitivity test - a=65, b=5, c=3, d=0 (n=73)
For the specificity test - a=23, b=2, c=24, d=682 (n=731)

#### akooha

##### New Member
Code:
spec_func <- function(a,b,c,n){
aa <- (n * (1 + 0.98))
bb <- ((a + c) * (0.98 ^2) - (a + b + 2 * c))
cc <- (c * (1 - 0.98) * (a + b + c) / n)
f <- ((sqrt((bb^2 - 4 * aa * cc) - bb) / (2 * aa)))
t <- ((a + b - (a + c) * 0.98) / sqrt(n * ((1 + 0.98) * f + (a + b + c) * (0.98 - 1) / n)))
return(t)
}

sens_func <- function(a,b,c,n){
aa <- (n * (1 + 0.9))
bb <- ((a + c) *(0.9 ^2) - (a + b + 2 * c))
cc <- (c * (1 - 0.9) * (a + b + c) / n)
f <- ((sqrt((bb^2 - 4 * aa * cc) - bb) / (2 * aa)))
t <- ((a + b - (a + c) * 0.9) / sqrt(n * ((1 + 0.9) * f + (a + b + c) * (0.9 - 1) / n)))
return(t)
}
I want to apologize for the code in advance. This is the first time I am using R, and the first time coding since middle school qBasic coding...

#### akooha

##### New Member
Is there anyone who could give me some pointers on what I am doing wrong?

#### hlsmith

##### Not a robit
What are the correct solutions?

Last edited:

#### hlsmith

##### Not a robit
I was working on adding more uppercase parenthesis to you code but got stressed so stopped. In particular I don't think the sqrt covers the B in the f calculation, but you have it under it. There may be other issues. I prefer more "()" then implied ordering.

#### akooha

##### New Member
Actually, I think that did the trick... I am a bit ashamed to have not seen that simple error. Getting z-values that are on the right scale. Thanks!

#### hlsmith

##### Not a robit
Can you post the final code - I am interested in this area. I still need to check out the paper.