Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confidence Interval for the negative effect #33

Open
sclab-shuo opened this issue Aug 2, 2024 · 0 comments
Open

Confidence Interval for the negative effect #33

sclab-shuo opened this issue Aug 2, 2024 · 0 comments

Comments

@sclab-shuo
Copy link

I suspect this error from the observation of a counterintuitive output for a simple mediation analysis with these 3 vectors as X, M, and Y variables. There is a significant negative effect after BCa correction of path c; however, the CI output always spans from negative to slightly positive number (e.g. -0.0213 to 0.0034). Please see the attached output saved from the "stats" variable.

I narrow this issue to the code from this script “bootbca_ci.m”. I understand this script works well for the positive effect, but maybe with a negative effect, the ci_upper and ci_lower should switched to obtain the asymmetric confidence interval before BCa manipulation.

a1 = z_0 + ( (z_0 + zalpha1) ./ (1 - a .* (z_0 + zalpha1)) );
p1 = normcdf(a1);

a2 = z_0 + ( (z_0 + zalpha2) ./ (1 - a .* (z_0 + zalpha2)) );
p2 = normcdf(a2);

ci_lower = prctile(bstat, 100 .* p1);
ci_upper = prctile(bstat, 100 .* p2);

% SC added: ------
ci_lower_n = prctile(bstat, 100 .* (1.-p2));
ci_upper_n = prctile(bstat, 100 .* (1.-p1));

testvalue = 0;
% prctile of the distribution below nullvalue (2-tailed)
% pct = min( [sum(bstat < testvalue); sum(bstat > testvalue)] ) ./ B;
pct_lowertail = sum(bstat < testvalue) ./ B;
pct_uppertail = sum(bstat > testvalue) ./ B;

% lower tail is smaller for positive effect. is_lowertail == 1 effects
% should be positive.
is_lowertail = pct_lowertail < pct_uppertail;

ci = [ci_lower ci_upper];

clear ci
for i=1:size(ci_lower, 1)
if is_lowertail(i) == 1
ci(i,1) = ci_lower(i,i);
ci(i,2) = ci_upper(i,i);
else
ci(i,1) = ci_lower_n(i,i);
ci(i,2) = ci_upper_n(i,i);
end
end

example data input and output file
https://drive.google.com/file/d/1X2iIecCE2WjQpyh2bqz3QmlmjsnT3i-0/view?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant