<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									How to calculate the Akaike Information Criterion (AIC) - General Discussion				            </title>
            <link>https://nm.dev/forums/nmdev-discussion/how-to-calculate-the-akaike-information-criterion-aic/</link>
            <description>NM DEV Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Fri, 10 Jul 2026 13:17:17 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>How to calculate the Akaike Information Criterion (AIC)</title>
                        <link>https://nm.dev/forums/nmdev-discussion/how-to-calculate-the-akaike-information-criterion-aic/#post-84</link>
                        <pubDate>Tue, 30 Jul 2024 16:51:25 +0000</pubDate>
                        <description><![CDATA[In below code I return the &quot;pValue&quot; in the &quot;AugmentedDickeyFuller&quot;. Now we can use different LagOrder parameters where it is important to choose the &quot;best&quot; possible lagOrder to return as acc...]]></description>
                        <content:encoded><![CDATA[<p>In below code I return the "pValue" in the "AugmentedDickeyFuller". <br />Now we can use different LagOrder parameters where it is important to choose the "best" possible lagOrder to return as accurate "pValue" as possible.<br /><br />Normally a good way to determine what LagOrder value to choose is by calculate the <br /><strong>Akaike Information Criterion (AIC)</strong>.<br /><br />Where the lowest found AIC would be a good pValue to choose.<br /><br />I am not sure how to calculate the AIC with the library in this context?<br />Below line is just pseudo code and that function do not exist but show the intent.<br /><br />Thank you!</p>
<pre contenteditable="false">CalculateAIC(statistic, lagOrder)</pre>
<pre contenteditable="false">TrendType P_1 = TrendType.CONSTANT;
ADFDistribution dist = P_1.getDistribution(array_MSFT.Length);

double minAIC = double.MaxValue;
int bestLagOrder = 0;

int maxLagOrder = 20;
for (int lagOrder = 0; lagOrder &lt;= maxLagOrder; lagOrder++) {
    AugmentedDickeyFuller ADFtest = new AugmentedDickeyFuller(array_MSFT, P_1, lagOrder, dist);
    double pValue = ADFtest.pValue();
    double statistic = ADFtest.statistics();

    //How to Implement AIC calculation? (Pseudo Code)
    double aic = CalculateAIC(statistic, lagOrder); 
    
    if (aic &lt; minAIC) {
        minAIC = aic;
        bestLagOrder = lagOrder;
    }
}</pre>]]></content:encoded>
						                            <category domain="https://nm.dev/forums/nmdev-discussion/">General Discussion</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://nm.dev/forums/nmdev-discussion/how-to-calculate-the-akaike-information-criterion-aic/#post-84</guid>
                    </item>
							        </channel>
        </rss>
		