How to calculate p.value for non inferiority study with R? I'll give a little background on my study. It is a non-inferiority study. We have to show that treatment A is non-inferior to treatment B with a delta acceptability margin of -2 for the outcome.
The estimated mean for the outcome in the group treatment B is 7 with with a standard deviation of 5.
The null hypothesis is Treatment A is inferior to treatment B ($\mu_A-\mu_B < -2$ the lower limit is less than $-2$)
The alternative hypothesis is that Treatment A is non-inferior to treatment B ($\mu_A-\mu_B > -2$ the lower limit is greater than $-2$)
I used t.test to compare the two groups:
t.test(mydata$outcome~mydata$traitement)
After comparison we obtained this results
Welch Two Sample t-test

data:  mydata$outcome by mydata$traitement
t = -0.88938, df = 258.81, p-value = 0.3746
alternative hypothesis: true difference in means between group Treatment A and Treatment B is not equal to 0
95 percent confidence interval:
 -2.133224  0.805804
sample estimates:
mean in group Treatment A mean in group Treatment B 
            8.390977             9.054688 

Our confidence interval tell us we did not prove non inferiority, cause its lower limit is $<-2$.
If I understand this p.value is not interpretable. Is it because this p.value represents the p.value of superiority? which can not prove our alternative hypothesis.
The international guideline recommends mainly the reporting of the confidence interval and much less the p.value in non-inferiority studies (even if the p.value is more and more encouraged in any type of study), but I believe that it is possible to calculate the p.value specific to the non-inferiority study (or am I mistaken?) Is this specific p.value valid? Is there an R function to calculate this p.value? Normally the alternative hypothesis is accepted if this p.value is $<0.05$. Is this the case?
 A: Tests for non-inferiority are basically asking "are the data consistent with an effect smaller than $\delta$".  In your case, $\delta=-2$.  We operationalize "consistent with" using a confidence interval, so as you mention we need to check if the confidence interval for the two groups covers -2.
That tells us how to determine the result for non-inferiority, but not how to compute a p value.  Well, we're interested in testing the null hypothesis that
$$ H_0: \mu_A - \mu_B \leq -2 $$
against the alternative
$$ H_A: \mu_A - \mu_B \gt -2 $$
So all we have to do to get a p value is perform the associated one sided test where -2 is our assumed difference under the null.  In R...
set.seed(0)

N <- 60

A <- rnorm(N, 0)
B <- rnorm(N, 1.5)

t.test(
  A, B,
  alternative = 'greater',
  mu=-2
)

    Welch Two Sample t-test

data:  A and B
t = 2.981, df = 114.87, p-value = 0.001754
alternative hypothesis: true difference in means is greater than -2
95 percent confidence interval:
 -1.783981       Inf
sample estimates:
  mean of x   mean of y 
-0.00191037  1.51127096 


P value is given in the output, and you can also see the associated confidence interval for the difference does not cover -2, which means we would reject the null that the difference is smaller than -2.
