Non linear mixed effects model – Fitting Time Activity Curve
Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me!Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me! Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me! non linear mixed effects, curve fitting MATLAB Answers — New Questions