TPCCLIB
Loading...
Searching...
No Matches
mtga.c File Reference

Multiple-time graphical analysis (including Patlak and Logan plots). More...

#include "libtpcmodel.h"

Go to the source code of this file.

Functions

int patlak_data (int data_nr, double *i, double *ii, double *c, double *x, double *y)
 
int logan_data (int data_nr, double *i, double *ii, double *c, double *ci, double k2, double *x, double *y)
 
int mtga_best_perp (double *x, double *y, int nr, double *slope, double *ic, double *ssd, int *fnr)
 

Detailed Description

Multiple-time graphical analysis (including Patlak and Logan plots).

Author
Vesa Oikonen

Definition in file mtga.c.

Function Documentation

◆ logan_data()

int logan_data ( int data_nr,
double * i,
double * ii,
double * c,
double * ci,
double k2,
double * x,
double * y )

Calculates Logan plot x,y values from the measured input and ROI concentration TACs.

Plot will not include data where: 1) any of the values is not available (NaN), 2) integral is negative at this or later point, 3) divider is too close to zero.

See also
patlak_data, img_logan, llsqperp, mtga_best_perp
Returns
Returns the number of acceptable Logan plot data pairs, or <0 in case of an error. Note that zero or one return values prevent the line fitting, but are here not considered as errors.
Parameters
data_nrNr of samples.
iArray of input concentrations.
iiArray of integrals (from zero to sample time) of input concentrations; if reference region input, then remember to consider the frame length.
cArray of ROI concentrations.
ciArray of ROI integrals (from zero to frame middle time).
k2Reference region k2; set to <=0 if not needed.
xPointer to preallocated memory (at least size dnr) where MTGA plot x values will be written.
yPointer to preallocated memory (at least size dnr) where MTGA plot y values will be written.

Definition at line 81 of file mtga.c.

99 {
100 int fi, plot_nr=0;
101 double divider_limit=1.0E-18;
102
103 if(data_nr<0 || i==NULL || ii==NULL || c==NULL || ci==NULL) return -1;
104 if(x==NULL || y==NULL) return -1;
105
106 for(fi=0; fi<data_nr; fi++) {
107 // check that all measured data is available
108 if(isnan(i[fi]) || isnan(ii[fi]) || isnan(c[fi]) || isnan(ci[fi])) continue;
109 if(!(i[fi]>-1.0E+30 && i[fi]<+1.0E+30)) continue;
110 if(!(ii[fi]>-1.0E+30 && ii[fi]<+1.0E+30)) continue;
111 if(!(c[fi]>-1.0E+30 && c[fi]<+1.0E+30)) continue;
112 if(!(ci[fi]>-1.0E+30 && ci[fi]<+1.0E+30)) continue;
113 // check that integrals have been >=0 all the time
114 if(ii[fi]<0.0) {plot_nr=0; continue;}
115 if(ci[fi]<0.0) {plot_nr=0; continue;}
116 // check that dividers are not too close to zero
117 if(fabs(c[fi])<divider_limit) continue;
118 // calculate plot x axis value
119 if(k2>0.0) x[plot_nr]=(ii[fi]+i[fi]/k2)/c[fi];
120 else x[plot_nr]=ii[fi]/c[fi];
121 if(!(x[plot_nr]>-1.0E+30 && x[plot_nr]<+1.0E+30)) continue;
122 // calculate plot y axis value
123 y[plot_nr]=ci[fi]/c[fi];
124 if(!(y[plot_nr]>-1.0E+30 && y[plot_nr]<+1.0E+30)) continue;
125 // so this plot data point is fine
126 plot_nr++;
127 }
128 return(plot_nr);
129}

Referenced by img_logan().

◆ mtga_best_perp()

int mtga_best_perp ( double * x,
double * y,
int nr,
double * slope,
double * ic,
double * ssd,
int * fnr )

Finds the best regression line to (x,y)-data, leaving points out from the beginning, because Gjedde-Patlak and Logan plots reach linearity at some later phase.

This function applies llsqperp() which is a non-iterative perpendicular line fitting routine.

See also
llsqperp(), logan_data, patlak_data
Returns
Returns 0, if successful, and <>0 in case of an error
Parameters
xPlot x axis values.
yPlot y axis values.
nrNr of plot data points.
slopeSlope is returned in here.
icY axis intercept is returned in here.
ssdSum of squared distances / fnr, or NULL if not needed.
fnrNumber of points in the best fit, or NULL if not needed.

Definition at line 141 of file mtga.c.

156 {
157 int from, to, ret, from_min, to_min;
158 double lic, lslope, lssd, ssd_min;
159
160 /* Search the plot range that gives the lowest ssd */
161 ssd_min=9.99E+99; from_min=to_min=-1;
162 for(from=0, to=nr-1; ((to-from)+1)>=MTGA_BEST_MIN_NR; from++) {
163 ret=llsqperp(x+from, y+from, (to-from)+1, &lslope, &lic, &lssd);
164 if(ret==0 && lssd<ssd_min) {
165 ssd_min=lssd; from_min=from; to_min=to;
166 *slope=lslope; *ic=lic; if(ssd!=NULL) *ssd=lssd;
167 }
168 }
169 if(from_min<0) {
170 if(fnr!=NULL) *fnr=0;
171 if(ssd!=NULL) *ssd=0.0;
172 return(5);
173 }
174 if(fnr!=NULL) *fnr=(to_min-from_min)+1;
175 return(0);
176}
int llsqperp(double *x, double *y, int nr, double *slope, double *ic, double *ssd)
Definition llsqwt.c:382
#define MTGA_BEST_MIN_NR

Referenced by img_logan(), and img_patlak().

◆ patlak_data()

int patlak_data ( int data_nr,
double * i,
double * ii,
double * c,
double * x,
double * y )

Calculates Gjedde-Patlak plot x,y values from the measured input and ROI concentration TACs.

Plot will not include data where: 1) any of the values is not available (NaN), 2) integral is negative at this or later point, 3) divider is too close to zero, 4) plot x value is negative.

See also
logan_data, img_patlak, llsqperp, mtga_best_perp
Returns
Returns the number of acceptable Gjedde-Patlak plot data pairs, or <0 in case of an error. Note that zero or one return values prevent the line fitting, but are here not considered as errors.
Parameters
data_nrNr of samples.
iArray of input concentrations.
iiArray of integrals (from zero to sample time) of input concentrations; if reference region input, then remember to consider the frame length.
cArray of ROI concentrations.
xPointer to preallocated memory (at least size dnr) where MTGA plot x values will be written.
yPointer to preallocated memory (at least size dnr) where MTGA plot y values will be written.

Definition at line 22 of file mtga.c.

38 {
39 int fi, plot_nr=0;
40 double divider_limit=1.0E-12;
41
42 if(data_nr<0 || i==NULL || ii==NULL || c==NULL || x==NULL || y==NULL)
43 return -1;
44 for(fi=0; fi<data_nr; fi++) {
45 // check that all measured data is available
46 if(isnan(i[fi]) || isnan(ii[fi]) || isnan(c[fi])) continue;
47 if(!(i[fi]>-1.0E+20 && i[fi]<+1.0E+20)) continue;
48 if(!(ii[fi]>-1.0E+20 && ii[fi]<+1.0E+20)) continue;
49 if(!(c[fi]>-1.0E+20 && c[fi]<+1.0E+20)) continue;
50 // check that integral has been >=0 all the time
51 if(ii[fi]<0.0) {plot_nr=0; continue;}
52 // check that dividers are not too close to zero
53 if(fabs(i[fi])<divider_limit) continue;
54 // calculate plot x axis value
55 x[plot_nr]=ii[fi]/i[fi];
56 if(!(x[plot_nr]>-1.0E+20 && x[plot_nr]<+1.0E+20)) continue;
57 if(x[plot_nr]<0.0) continue;
58 // calculate plot y axis value
59 y[plot_nr]=c[fi]/i[fi];
60 if(!(y[plot_nr]>-1.0E+20 && y[plot_nr]<+1.0E+20)) continue;
61 // so this plot data point is fine
62 plot_nr++;
63 }
64 return(plot_nr);
65}

Referenced by img_patlak().