264 |
cmd.v_id); |
cmd.v_id); |
265 |
} |
} |
266 |
|
|
|
#ifndef NO_CHARTS |
|
267 |
if ( cmd.a_plot[XMN_PLT_HISTOGRAM] ) |
if ( cmd.a_plot[XMN_PLT_HISTOGRAM] ) |
268 |
{ |
{ |
269 |
for ( v = 0 ; v < n_dependent_vars; ++v ) |
for ( v = 0 ; v < n_dependent_vars; ++v ) |
279 |
&normal, 0); |
&normal, 0); |
280 |
} |
} |
281 |
} |
} |
|
#endif |
|
282 |
|
|
283 |
} |
} |
284 |
|
|
330 |
if ( cmd.a_plot[XMN_PLT_NPPLOT] ) |
if ( cmd.a_plot[XMN_PLT_NPPLOT] ) |
331 |
np_plot(&(*fs)->m[v], s); |
np_plot(&(*fs)->m[v], s); |
332 |
|
|
|
#ifndef NO_CHARTS |
|
333 |
if ( cmd.a_plot[XMN_PLT_HISTOGRAM] ) |
if ( cmd.a_plot[XMN_PLT_HISTOGRAM] ) |
334 |
{ |
{ |
335 |
struct normal_curve normal; |
struct normal_curve normal; |
341 |
histogram_plot((*fs)->m[v].histogram, |
histogram_plot((*fs)->m[v].histogram, |
342 |
s, &normal, 0); |
s, &normal, 0); |
343 |
} |
} |
|
#endif |
|
344 |
|
|
345 |
} /* for ( fs .... */ |
} /* for ( fs .... */ |
346 |
|
|
1626 |
struct variable **vars, int n_vars, |
struct variable **vars, int n_vars, |
1627 |
const struct variable *id) |
const struct variable *id) |
1628 |
{ |
{ |
1629 |
#ifndef NO_CHARTS |
|
1630 |
int i; |
int i; |
1631 |
struct factor_statistics **fs ; |
struct factor_statistics **fs ; |
1632 |
|
|
1640 |
{ |
{ |
1641 |
double y_min = DBL_MAX; |
double y_min = DBL_MAX; |
1642 |
double y_max = -DBL_MAX; |
double y_max = -DBL_MAX; |
1643 |
struct chart ch; |
struct chart *ch; |
1644 |
|
|
1645 |
chart_initialise(&ch); |
ch = chart_create(); |
1646 |
|
|
1647 |
const char *s = factor_to_string(fctr, *fs, 0 ); |
const char *s = factor_to_string(fctr, *fs, 0 ); |
1648 |
|
|
1649 |
chart_write_title(&ch, s); |
chart_write_title(ch, s); |
1650 |
|
|
1651 |
for ( i = 0 ; i < n_vars ; ++i ) |
for ( i = 0 ; i < n_vars ; ++i ) |
1652 |
{ |
{ |
1654 |
y_min = min(y_min, (*fs)->m[i].min); |
y_min = min(y_min, (*fs)->m[i].min); |
1655 |
} |
} |
1656 |
|
|
1657 |
boxplot_draw_yscale(&ch, y_max, y_min); |
boxplot_draw_yscale(ch, y_max, y_min); |
1658 |
|
|
1659 |
for ( i = 0 ; i < n_vars ; ++i ) |
for ( i = 0 ; i < n_vars ; ++i ) |
1660 |
{ |
{ |
1661 |
|
|
1662 |
const double box_width = (ch.data_right - ch.data_left) |
const double box_width = (ch->data_right - ch->data_left) |
1663 |
/ (n_vars * 2.0 ) ; |
/ (n_vars * 2.0 ) ; |
1664 |
|
|
1665 |
const double box_centre = ( i * 2 + 1) * box_width |
const double box_centre = ( i * 2 + 1) * box_width |
1666 |
+ ch.data_left; |
+ ch->data_left; |
1667 |
|
|
1668 |
boxplot_draw_boxplot(&ch, |
boxplot_draw_boxplot(ch, |
1669 |
box_centre, box_width, |
box_centre, box_width, |
1670 |
&(*fs)->m[i], |
&(*fs)->m[i], |
1671 |
var_to_string(vars[i])); |
var_to_string(vars[i])); |
1673 |
|
|
1674 |
} |
} |
1675 |
|
|
1676 |
chart_finalise(&ch); |
chart_submit(ch); |
1677 |
|
|
1678 |
} |
} |
|
#endif |
|
1679 |
} |
} |
1680 |
|
|
1681 |
|
|
1689 |
int n_vars, |
int n_vars, |
1690 |
const struct variable *id) |
const struct variable *id) |
1691 |
{ |
{ |
1692 |
#ifndef NO_CHARTS |
|
1693 |
int i; |
int i; |
1694 |
|
|
1695 |
for ( i = 0 ; i < n_vars ; ++i ) |
for ( i = 0 ; i < n_vars ; ++i ) |
1696 |
{ |
{ |
1697 |
struct factor_statistics **fs ; |
struct factor_statistics **fs ; |
1698 |
struct chart ch; |
struct chart *ch; |
1699 |
|
|
1700 |
chart_initialise(&ch); |
ch = chart_create(); |
1701 |
|
|
1702 |
boxplot_draw_yscale(&ch, totals[i].max, totals[i].min); |
boxplot_draw_yscale(ch, totals[i].max, totals[i].min); |
1703 |
|
|
1704 |
if ( fctr ) |
if ( fctr ) |
1705 |
{ |
{ |
1708 |
for ( fs = fctr->fs ; *fs ; ++fs ) |
for ( fs = fctr->fs ; *fs ; ++fs ) |
1709 |
++n_factors; |
++n_factors; |
1710 |
|
|
1711 |
chart_write_title(&ch, _("Boxplot of %s vs. %s"), |
chart_write_title(ch, _("Boxplot of %s vs. %s"), |
1712 |
var_to_string(vars[i]), var_to_string(fctr->indep_var[0]) ); |
var_to_string(vars[i]), var_to_string(fctr->indep_var[0]) ); |
1713 |
|
|
1714 |
for ( fs = fctr->fs ; *fs ; ++fs ) |
for ( fs = fctr->fs ; *fs ; ++fs ) |
1716 |
|
|
1717 |
const char *s = factor_to_string_concise(fctr, *fs); |
const char *s = factor_to_string_concise(fctr, *fs); |
1718 |
|
|
1719 |
const double box_width = (ch.data_right - ch.data_left) |
const double box_width = (ch->data_right - ch->data_left) |
1720 |
/ (n_factors * 2.0 ) ; |
/ (n_factors * 2.0 ) ; |
1721 |
|
|
1722 |
const double box_centre = ( f++ * 2 + 1) * box_width |
const double box_centre = ( f++ * 2 + 1) * box_width |
1723 |
+ ch.data_left; |
+ ch->data_left; |
1724 |
|
|
1725 |
boxplot_draw_boxplot(&ch, |
boxplot_draw_boxplot(ch, |
1726 |
box_centre, box_width, |
box_centre, box_width, |
1727 |
&(*fs)->m[i], |
&(*fs)->m[i], |
1728 |
s); |
s); |
1730 |
} |
} |
1731 |
else |
else |
1732 |
{ |
{ |
1733 |
const double box_width = (ch.data_right - ch.data_left) / 3.0; |
const double box_width = (ch->data_right - ch->data_left) / 3.0; |
1734 |
const double box_centre = (ch.data_right + ch.data_left) / 2.0; |
const double box_centre = (ch->data_right + ch->data_left) / 2.0; |
1735 |
|
|
1736 |
chart_write_title(&ch, _("Boxplot")); |
chart_write_title(ch, _("Boxplot")); |
1737 |
|
|
1738 |
boxplot_draw_boxplot(&ch, |
boxplot_draw_boxplot(ch, |
1739 |
box_centre, box_width, |
box_centre, box_width, |
1740 |
&totals[i], |
&totals[i], |
1741 |
var_to_string(vars[i]) ); |
var_to_string(vars[i]) ); |
1742 |
|
|
1743 |
} |
} |
1744 |
|
|
1745 |
chart_finalise(&ch); |
chart_submit(ch); |
1746 |
} |
} |
|
#endif |
|
1747 |
} |
} |
1748 |
|
|
1749 |
|
|
1752 |
void |
void |
1753 |
np_plot(const struct metrics *m, const char *factorname) |
np_plot(const struct metrics *m, const char *factorname) |
1754 |
{ |
{ |
|
#ifndef NO_CHARTS |
|
1755 |
int i; |
int i; |
1756 |
double yfirst=0, ylast=0; |
double yfirst=0, ylast=0; |
1757 |
|
|
1758 |
/* Normal Plot */ |
/* Normal Plot */ |
1759 |
struct chart np_chart; |
struct chart *np_chart; |
1760 |
|
|
1761 |
/* Detrended Normal Plot */ |
/* Detrended Normal Plot */ |
1762 |
struct chart dnp_chart; |
struct chart *dnp_chart; |
1763 |
|
|
1764 |
/* The slope and intercept of the ideal normal probability line */ |
/* The slope and intercept of the ideal normal probability line */ |
1765 |
const double slope = 1.0 / m->stddev; |
const double slope = 1.0 / m->stddev; |
1769 |
if ( m->n_data == 0 ) |
if ( m->n_data == 0 ) |
1770 |
return ; |
return ; |
1771 |
|
|
1772 |
chart_initialise(&np_chart); |
np_chart = chart_create(); |
1773 |
chart_write_title(&np_chart, _("Normal Q-Q Plot of %s"), factorname); |
dnp_chart = chart_create(); |
1774 |
chart_write_xlabel(&np_chart, _("Observed Value")); |
|
1775 |
chart_write_ylabel(&np_chart, _("Expected Normal")); |
if ( !np_chart || ! dnp_chart ) |
1776 |
|
return ; |
1777 |
|
|
1778 |
|
chart_write_title(np_chart, _("Normal Q-Q Plot of %s"), factorname); |
1779 |
|
chart_write_xlabel(np_chart, _("Observed Value")); |
1780 |
|
chart_write_ylabel(np_chart, _("Expected Normal")); |
1781 |
|
|
1782 |
chart_initialise(&dnp_chart); |
|
1783 |
chart_write_title(&dnp_chart, _("Detrended Normal Q-Q Plot of %s"), |
chart_write_title(dnp_chart, _("Detrended Normal Q-Q Plot of %s"), |
1784 |
factorname); |
factorname); |
1785 |
chart_write_xlabel(&dnp_chart, _("Observed Value")); |
chart_write_xlabel(dnp_chart, _("Observed Value")); |
1786 |
chart_write_ylabel(&dnp_chart, _("Dev from Normal")); |
chart_write_ylabel(dnp_chart, _("Dev from Normal")); |
1787 |
|
|
1788 |
yfirst = gsl_cdf_ugaussian_Pinv (m->wvp[0]->rank / ( m->n + 1)); |
yfirst = gsl_cdf_ugaussian_Pinv (m->wvp[0]->rank / ( m->n + 1)); |
1789 |
ylast = gsl_cdf_ugaussian_Pinv (m->wvp[m->n_data-1]->rank / ( m->n + 1)); |
ylast = gsl_cdf_ugaussian_Pinv (m->wvp[m->n_data-1]->rank / ( m->n + 1)); |
1796 |
double x_upper = max(m->max, (ylast - intercept) / slope) ; |
double x_upper = max(m->max, (ylast - intercept) / slope) ; |
1797 |
double slack = (x_upper - x_lower) * 0.05 ; |
double slack = (x_upper - x_lower) * 0.05 ; |
1798 |
|
|
1799 |
chart_write_xscale(&np_chart, x_lower - slack, x_upper + slack, 5); |
chart_write_xscale(np_chart, x_lower - slack, x_upper + slack, 5); |
1800 |
|
|
1801 |
chart_write_xscale(&dnp_chart, m->min, m->max, 5); |
chart_write_xscale(dnp_chart, m->min, m->max, 5); |
1802 |
|
|
1803 |
} |
} |
1804 |
|
|
1805 |
chart_write_yscale(&np_chart, yfirst, ylast, 5); |
chart_write_yscale(np_chart, yfirst, ylast, 5); |
1806 |
|
|
1807 |
{ |
{ |
1808 |
/* We have to cache the detrended data, beacause we need to |
/* We have to cache the detrended data, beacause we need to |
1809 |
find its limits before we can plot it */ |
find its limits before we can plot it */ |
1810 |
double *d_data; |
double *d_data; |
1811 |
d_data = xmalloc (m->n_data * sizeof(double)); |
d_data = xmalloc (m->n_data * sizeof(double)); |
1812 |
double d_max = -DBL_MAX; |
double d_max = -DBL_MAX; |
1813 |
double d_min = DBL_MAX; |
double d_min = DBL_MAX; |
1814 |
for ( i = 0 ; i < m->n_data; ++i ) |
for ( i = 0 ; i < m->n_data; ++i ) |
1815 |
{ |
{ |
1816 |
const double ns = gsl_cdf_ugaussian_Pinv (m->wvp[i]->rank / ( m->n + 1)); |
const double ns = gsl_cdf_ugaussian_Pinv (m->wvp[i]->rank / ( m->n + 1)); |
1817 |
|
|
1818 |
chart_datum(&np_chart, 0, m->wvp[i]->v.f, ns); |
chart_datum(np_chart, 0, m->wvp[i]->v.f, ns); |
1819 |
|
|
1820 |
d_data[i] = (m->wvp[i]->v.f - m->mean) / m->stddev - ns; |
d_data[i] = (m->wvp[i]->v.f - m->mean) / m->stddev - ns; |
1821 |
|
|
1822 |
if ( d_data[i] < d_min ) d_min = d_data[i]; |
if ( d_data[i] < d_min ) d_min = d_data[i]; |
1823 |
if ( d_data[i] > d_max ) d_max = d_data[i]; |
if ( d_data[i] > d_max ) d_max = d_data[i]; |
1824 |
} |
} |
1825 |
chart_write_yscale(&dnp_chart, d_min, d_max, 5); |
chart_write_yscale(dnp_chart, d_min, d_max, 5); |
1826 |
|
|
1827 |
for ( i = 0 ; i < m->n_data; ++i ) |
for ( i = 0 ; i < m->n_data; ++i ) |
1828 |
chart_datum(&dnp_chart, 0, m->wvp[i]->v.f, d_data[i]); |
chart_datum(dnp_chart, 0, m->wvp[i]->v.f, d_data[i]); |
1829 |
|
|
1830 |
free(d_data); |
free(d_data); |
1831 |
} |
} |
1832 |
|
|
1833 |
chart_line(&np_chart, slope, intercept, yfirst, ylast , CHART_DIM_Y); |
chart_line(np_chart, slope, intercept, yfirst, ylast , CHART_DIM_Y); |
1834 |
chart_line(&dnp_chart, 0, 0, m->min, m->max , CHART_DIM_X); |
chart_line(dnp_chart, 0, 0, m->min, m->max , CHART_DIM_X); |
1835 |
|
|
1836 |
chart_finalise(&np_chart); |
chart_submit(np_chart); |
1837 |
chart_finalise(&dnp_chart); |
chart_submit(dnp_chart); |
|
#endif |
|
1838 |
} |
} |
1839 |
|
|
1840 |
|
|