Skip to content

Confidence Interval for the negative effect #33

@sclab-shuo

Description

@sclab-shuo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions