I`m writing a code calibration to calculate the partial safety factors. The Error here is **DS unused argument.** I can`

t discover the error here,

```
Codecal <- function(S,DS,CM,Beta,X){
# COMPUTE PARTIAL SAFETY FACTORS FOR CODE CALIBRATION
#
# INPUT
#
# X = [n x 1] Ratios of Design points according to the given mean ratio
# S = [n x 1] Standard Deviation OF DISTRIBUTION OF X
# DS = [n x 1] DISTRIBUTION TYPE [1 = Normal, 2 = Lognorm, 3 = Gumbel TypeI]
# CM = [n X n] CORRELATION MATRIX IF ANY CORRELATION EXISTS
# Beta = [1 x 1] RELIABILITY INDEX TARGET
#
# OUTPUT
#gaa = [n x 1] DESIGN FACTORS
#==========================================================================
#
M <- X
nMax = 100 # NUMBER OF ITERATIONS
tol= 1e-3 # TOLERANCE ON GAMMA
CHK <- F # STOPPING CONDITION
nVr <- length(X) # NUMBER OF RANDOM VARIABLES
Sz = S; # INITIALIZE VECTOR OF STANDARD DEVIATION
Mz = M; # INITIALIZE VECTOR OF MEAN
ga= Inf
# TRANSFORM Z = (X - M)/S => X = M + S*Z
itr <- 0
while(!CHK){
# COMPUTE
#This additional part OF Rakwitz-Fiessler if the distribution is NOT normal
for(i1 in seq(1:nVr)){ # NORM
# IF NORM VARIABLE Mz AND Sz REMAIN THE SAME
if(DS[i1] == 2){ # LOGNORM
S0 <- sqrt(log(1 + (S[i1]/M[i1])^2))
M0 <- log(M[i1]) - 0.5*S0^2
Sz[i1] <- (1/dlnorm(x = X[i1],meanlog = M0,sdlog = S0)) * dnorm(x = qnorm(p = plnorm(q = X[i1],meanlog = M0, sdlog = S0),mean = 0,sd = 1),mean = 0,sd = 1)
Mz[i1] <- X[i1] - Sz[i1]*qnorm(p = plnorm(q = X[i1],meanlog = M0, sdlog = S0),mean = 0,sd = 1)
}else if(DS[i1] == 3){ # GUMBEL TYPE I
S0 = sqrt(pi^2 / (6*S[i1]^2))
M0 = M[i1] - 0.5772/S0
Fx <- exp(-exp(-S0*(X[i1]-M0)))
fx <- S0 * (exp(-S0*(X[i1]-M0)))*Fx
Sz[i1] <- (1/fx) * dnorm(x = qnorm(p = Fx))
Mz[i1] <- X[i1] - Sz[i1]*qnorm(p = Fx)
}
}
Dummy <- LimitStateFun(X,Sz)
Z = (Dummy$Xp - Mz)/Sz
ga0 <-ga*Dummy$Gr / as.numeric(sqrt(Dummy$Gr %*% Dummy$Gr))
if(abs(ga0-ga) <= tol || itr == nMax){
CHK <- T
}
itr <- itr + 1
ga <- ga0
Z <- Beta * Dummy$Gr
X <- Mz + Z * Sz
ga=X/Mz
}
Out <- list(ga=ga)
#
#' Limit State Function
#
LimitStateFun <- function(X,S){
# COMPUTE X(n) FROM LIMITE STATE FUNCTION OF X[1]...X(n-1)
# INPUT
#
# X = INITIAL DESIGN POINT
# S = STANDARD DEVIATION OF NORMALIZED VARIATES OF Z
# P = VECTOR OF PARAMETERS
#
Grd <- rep(0,length(X))
# GRADIENT VECTOR
Grd = P*S; Grd[1] = -Grd[1];
# G(Z) = P[1]*X[1] - P[1]*X[2] - P[2]*X[3] =0
X[1] = X[2]+X[3]
# GRADIENT VECTOR
Grd[1] = -S[1]
Grd[2] = S[2]
Grd[3] = S[3]
}
Out <- data.frame(Gr = Grd)
Out
}
```