Hello here. I am new to R but I want to do mediation analysis on complex survey data using med.fit.brr in the medsurvey package. I did some reading about this method. The method requires use of Balanced Replication weights. In my data, I have the normal survey design elements (psu, strata and weight variables).

I tried to use this to create balanced replication weights;

```
meddesign<-svydesign(data=med,
id=~psu, strata=~kstrata,
weights=~pooled_wt2, nest=TRUE)
med.brr<-
as.svrepdesign(
meddesign ,
type = "BRR" ,
mse = TRUE ,
compress = FALSE)
```

I got this error:-

```
# Error in brrweights(design$strata[, 1], design$cluster[, 1], ..., fay.rho = fay.rho, :
# Can't split with odd numbers of PSUs in a stratum
```

Qn1. How can I address this?

To try to solve this, I used the Jackknife replication for stratified samples;

```
med.Jkn<-
as.svrepdesign(
meddesign ,
type = "JKn" ,
mse = TRUE ,
compress = FALSE)
```

And weights were successfully created and named "repweights".

I then tried to use these weights to run mediation analysis using the med.fit.BRR;

```
# Specification of the model
model2<- '# outcome
HE_glu~ u0*1 + c*diinormal + b*HE_hsCRP + age+ sex+ N_EN + DM_fh + HE_HP
# mediator
HE_hsCRP~ u1*1 + a*diinormal +age +sex+ N_EN+HE_BMI+HE_HP+DM_fh
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b) '
# Mediation analysis
Fit.brr<-med.fit.BRR(model=model2, data=med,
mwgtname= pooled_wt2,
repwgtnames= repweights,
fayfactor=0.5, parallel='parallel', ncore=2)
```

I got this error

```
# Error in med.fit.BRR(model = model2, data = med, mwgtname = pooled_wt2, : value of HE_gluis not numerical
```

I am sorry it is a long procedure but I am kindly requesting for assistance.