Ejemplo de script: Regresión: crear una tabla con intervalos de confianza
Este script calcula el intervalo de confianza para un rango de valores, basándose en un análisis de regresión lineal. Los resultados se presentan en una tabla con formato.
// regional settings
$decimalsymbol= '.' ;
$listseparator= ',' ;
//
cls;
clear data;
<data>
Timepoint Result
0 0.11
3 0.17
6 0.31
9 0.4
12 0.5
18 1.03
24 1.06
</data>
varx =TimePoint;
vary =Result;
slope =VSLOPE(varx,vary);
intercept =VINTERCEPT(varx,vary);
n =VCOUNT(varx,ISNUMBER(vary));
meanX =VAVERAGE(varx);
devsqX =VDEVSQ(varx);
steyx =VSTEYX(vary,varx);
alpha =0.05;
t =TINV(alpha,n-2);
table(tab);
AppendRow(tab, 'x', 'y', 'CI Low', 'CI High');
x=0;
while (x<=24) {
y=intercept+x*slope;
s=steyx*sqrt(1/n+(x-meanX)^2/devsqX);
lo=y-t*s;
hi=y+t*s;
AppendRow(tab,x,y,lo,hi);
x=x+2;
}
FormatTable(tab, '3');
FormatTableColumn(tab,1, '0');
FormatTableRow(tab,1, 'shaded bold 0');
?tab;
Salida
| x | y | CI Low | CI High |
| 0 | 0.053 | -0.105 | 0.212 |
| 2 | 0.142 | 0.003 | 0.282 |
| 4 | 0.231 | 0.108 | 0.354 |
| 6 | 0.321 | 0.211 | 0.430 |
| 8 | 0.410 | 0.310 | 0.510 |
| 10 | 0.499 | 0.403 | 0.595 |
| 12 | 0.588 | 0.490 | 0.686 |
| 14 | 0.677 | 0.571 | 0.783 |
| 16 | 0.766 | 0.647 | 0.885 |
| 18 | 0.855 | 0.720 | 0.990 |
| 20 | 0.944 | 0.791 | 1.097 |
| 22 | 1.033 | 0.861 | 1.206 |
| 24 | 1.122 | 0.929 | 1.316 |