MATLAB Answers

Calculate confidence interval of data sets.

7 ビュー (過去 30 日間)
Rajvi Amle
Rajvi Amle 2021 年 5 月 23 日
コメント済み: dpb 2021 年 5 月 23 日
I have n=10 and calculated random values with two variables (SYSTEM.m_BW and SYSTEM.w_L). 2 ODEs and a loop is mentioned to run for every 10 iterations (for i=1:10) and plotted the graph for the same. Now I want to calculate mean of all the lines from the plot of simulated data (x(:,2)+x(:,1)) mentioned in the loop, then save x & t (time span) in a matrix to calculate and plot confidence interval from the simulated data given in the code (x(:,2)+x(:,1)) for every x= 1 to 10 lines. How do I calculate the mean of all the lines in the plot and how do I calculate confidence interval based on the mean and standard deviation of the data points? I want the graph something as given in attached graph with confidence interval of 95% calculated from mean shown with the upper and lower boundaries.
Could someone please help me with this, it would be really helpful and appreciated. Following is the given code, i have worked on so far:
function toy_example
clear all;
close all;
% Body weight and organ weight fraction [Min Max] (random numbers for 10 mice)
SYSTEM.m_BW= 24+(28-24).*rand(10,1); % Body weight [g]
SYSTEM.w_L= 0.0417+(0.0681-0.0417).*rand(10,1); % Liver [g/g]
SYSTEM.w_S= 0.019+(0.0051-0.0019).*rand(10,1); % Spleen [g/g]
SYSTEM.w_K= 0.015+(0.0184-0.015).*rand(10,1); % Kidney [g/g]
SYSTEM.w_Lu= 0.0065+(0.0081-0.0065).*rand(10,1); % Lung [g/g]
SYSTEM.w_BR= 0.0139+(0.0191-0.0139).*rand(10,1); % Brain [g/g]
SYSTEM.w_Blood= 0.049+(0.049-0.049).*rand(10,1); % Blood [g/g]
SYSTEM.w_Plasma= 0.029+(0.029-0.029).*rand(10,1); % Plasma [g/g]
EXP.t=[0 6 12 18 24]; %h (time for blood pharmacokinetics)
DRUG.w_Au_iv = [15E-03 183E-03 693E-03 1058E-03]; %[mg/g]
DRUG.m_Au_iv = DRUG.w_Au_iv.*SYSTEM.m_BW(1); %[mg]
EXP.Blood_15=(([16.32 3.8 2.87 2.33 2.06]/100).*SYSTEM.m_BW.*SYSTEM.w_Plasma.*DRUG.w_Au_iv(1).*SYSTEM.m_BW)./(SYSTEM.m_BW.*SYSTEM.w_Plasma);
EXP.Blood_183=(([31.3 1.48 0.98 0.84 0.8]/100).*SYSTEM.m_BW.*SYSTEM.w_Plasma.*DRUG.w_Au_iv(2).*SYSTEM.m_BW)./(SYSTEM.m_BW.*SYSTEM.w_Plasma);
EXP.Blood_1058=(([57.82 0.42 0.35 0.35 0.35]/100).*SYSTEM.m_BW.*SYSTEM.w_Plasma.*DRUG.w_Au_iv(4).*SYSTEM.m_BW)./(SYSTEM.m_BW.*SYSTEM.w_Plasma);
hold on
for i=1:10
MAT=[SYSTEM.m_BW(i) SYSTEM.w_L(i)]';
[t,x]=ode15s(@ode_toy, tspan, x0, [ ], MAT);
plot(t,(x(:,2)+x(:,1)),'-.','Color', 'blue', 'LineWidth', 2)
function dxdt = ode_toy(t,x,SYSTEM)
%% Split State Vector
%% ODE system
% Dosing
dm_Au_A_dt=m_BW - w_L*m_Au_A;
dx(1) = dm_Au_A_dt;
dm_Au_V_dt= w_L - m_BW*m_Au_V;
dx(2) = dm_Au_V_dt;
dxdt = dx(:);
  3 件のコメント
dpb 2021 年 5 月 23 日
I'm really pressed for time, so the following is untested "air code" typed in here...hopefully it'll be enough to give you the idea...
t=cell(1,10); y=t; % preallocate the output cell arrays as row to hold column vectors
hold on
tspan=[0:24]; % invariant, don't need in loop
for i=1:10
MAT=[SYSTEM.m_BW(i) SYSTEM.w_L(i)]';
[t{i},x]=ode15s(@ode_toy, tspan, x0,[], MAT); % assign output to cell arrays
y{i}=(x(:,2)+x(:,1); % compute, save y also
plot(t{i},y{i},'-.','Color', 'blue', 'LineWidth', 2)
IFF the returned t vector is the same for every iteration, then you can convert it to a single vector as would all be redundant and turn y into a normal 2D array.
Then the mean, sd of mean would be
mny=mean(cell2mat(y),2); % convert cell array to matrix, mean by row
sdmny=mny/size(y,2); % std dev of mean(y) is mean(y)/nObs


回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by