<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/regression-model-with-auto-correlated-errors-part-1-the-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/fitting-a-simple-regression-model-with-auto-correlated-errors-an-astrological-example-part-1-the-data/"> DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The assumptions of simple linear regression include the assumption that the errors are independent with constant variance. Fitting a simple regression when the errors are auto-correlated requires techniques from the field of time series. If you are interested in fitting a model to an evenly spaced series where the terms are auto-correlated, I have given below an example of fitting such a model.</p>
<h2>The Astronomical/Astrological Hypotheses to be Tested</h2>
<p>For some years now, I have been interested in the possible astrological influence of a composite astronomical point, the mean over the shortest arc of the celestial longitudes of the celestial bodies Juno, Ceres, Vesta, and Pallas. I wanted to see if the point affected divorce rates. In astrology, planets rule zodiacal signs. In older systems of astrology, from before the discoveries of the outer planets, each of the five known planets (Mercury, Venus, Mars, Jupiter, and Saturn – we exclude the earth) ruled two signs. As Uranus, Neptune, and Pluto were discovered, the planets were given rulership over one of Saturn’s, Jupiter’s, and Mars’s signs, respectively. In 1977, the celestial body Chiron was discovered. Some astrologers give Chiron the rulership of one of Mercury’s signs, which would leave Venus as the only planet with dual rulership.</p>
<p>The celestial bodies Juno, Ceres, Vesta, and Pallas were discovered in the early 1800’s. Referencing Roman mythology, some astrologers feel that the discoveries of Juno – the wife, Ceres – the mother, Vesta – the sister, and Pallas – the daughter synchronized with the emergence of the struggle for the full participation of women within society. Venus (which, from the above, is for some astrologers the only planet that still rules two signs) is one of the traditional rulers of women in astrology. The two signs that Venus rules are those associated with money and marriage. I had thought that the mean of the celestial longitudes over of the shortest arc connecting Juno, Ceres, Vesta, and Pallas might be the ruler of the sign of marriage, since Juno, Ceres, Vesta, and Pallas refer to female archetypes. Then Venus would just rule the sign of money. The mean over the shortest arc jumps 90 degrees or 180 degrees from time to time. To test the hypothesis, I had thought that the jump point of the mean over the shortest arc might be related to divorce. An ephemeris for the average, which I call Vulcan – as well as a point I call Cent, from 1900 to 2050, can be found here – <a target="_blank" rel="nofollow" href="http://vanwardstat.com/vulccent.8.5.16.pdf">here</a>. </p>
<h2>The Data Sets: Divorce Counts for Iowa and the Jump Points</h2>
<p>I created a data vector of monthly divorce counts in Iowa from August of 2006 to November of 2009 and a vector based on the jump points of the mean over the shortest arc of the celestial longitudes of Juno, Vesta, Ceres, and Pallas. The divorce counts were adjusted for the number of business days in a month. The adjusted divorce counts are the dependent variable. The independent variables are the usual column of ones to fit a mean and a column which linearly increases as time increases after a jump point and which is set back to zero at each jump point.</p>
<p>First enter monthly divorce counts for Iowa from 8/06 to 11/09</p>
<pre>
div.ts = ts(c(619, 704, 660, 533, 683, 778, 541, 
         587, 720, 609, 622, 602, 639, 599, 657, 
         687, 646, 608, 571, 768, 703, 638, 743, 
         693, 624, 694, 660, 522, 639, 613, 446, 
         863, 524, 564, 716, 635, 649, 565, 567, 
         626), start=c(2006,8), freq=12) </pre>
<p>Next enter the break point information: the number of days from the last shift</p>
<pre>
vulcan.ts = ts(c(63, 94, 124, 155, 185, 216, 247, 
            275, 306, 336, 367, 397, 428, 459, 489, 
            520, 550, 581, 612, 641, 672, 702, 733, 
            763, 19, 50, 80, 4, 34, 65, 96, 124, 
            155, 185, 216, 246, 277, 308, 3,  34), 
            start=c(2006,8), freq=12)</pre>
<p>The divorce data is from the Center for Disease Control and Prevention website, from the National Vital Statistics Report <a target="_blank" rel="nofollow" href="http://www.cdc.gov/nchs/products/nvsr.htm">page</a>. I took marriage and divorce data for Iowa from the reports from August of 2006 to November of 2009. The divorce data for April of 2008 was 161, which was unusually small. In my analyses, I replaced the number with 703, the average of the numbers on either side.</p>
<p>The average of the longitudes of the four major asteroids, Juno, Ceres, Pallas, and Vesta (yes, I know Ceres is now a dwarf planet) along the shortest arc will jump by 90 or 180 degrees from time to time. The variable I use is the time in days from the last day in which a jump occurred. Since the marriage and divorce data is monthly, each data point is assumed to be at the 15th of the month. </p>
<p>The question of interest is, are the jump points associated the divorce counts in a linear way? Since the months are not of equal length, I have adjusted the divorce counts by dividing the divorce count for a month by the number of state business days in the month and multiplying the result by the average number of state business days in a month over the observed months. </p>
<p>First create a vector of days of the week, with 1 for Sunday, 2 for Monday, etc. 8/06 started on a Tuesday.</p>
<pre>
wks = c(3:7, rep(1:7, 173), 1:2) </pre>
<p>Next create a daily vector for the months, with 1 for for the first month, 2 for the second month, etc.</p>
<pre>
mns = c(8:12, rep(1:12,2), 1:11)
mns.d = 1:40
mn =  c(31,28,31,30,31,30,31,31,30,31,30,31)
mns.dys = rep(mns.d,mn[mns]) </pre>
<p>Add 2008 leap day</p>
<pre>mns.dys = c(mns.dys[1:553], 19, mns.dys[554:1217]) </pre>
<p>Next remove Sundays and Saturdays</p>
<pre>mns.dys.r = mns.dys[wks>1 &amp; wks&lt;7]</pre>
<p>Next use <code>table()</code> to count the weekdays in each month</p>
<pre>mns.dys.s = c(table(mns.dys.r))</pre>
<p>Next enter the number of government holidays in each of the 40 months</p>
<pre>hol = c(0, 1, 0, 3, 1, 2, 0, 0, 0, 1, 0, 1, 
        0, 1, 0, 3, 1, 2, 0, 0, 0, 1, 0, 1, 
        0, 1, 0, 3, 1, 2, 0, 0, 0, 1, 0, 1, 
        0, 1, 0, 3)</pre>
<p>Next subtract out the holidays</p>
<pre>mns.dys.s = mns.dys.s - hol</pre>
<p>Next adjust the divorce counts</p>
<pre>div.a.ts = div.ts * mean(mns.dys.s)/mns.dys.s</pre>
<p>The holidays I excluded are New Year’s Day, Martin Luther King Day, Memorial Day, Independence Day, Labor Day, Veteran’s Day, the two days for Thanksgiving, and Christmas Day, as these days were state holidays in Iowa in 2012. </p>
<p>The number of state business days that I found for each month are given in the table below.</p>
<table>
<tr>
<td></td>
<td>Jan</td>
<td>Feb</td>
<td>Mar</td>
<td>Apr</td>
<td>May</td>
<td>Jun</td>
<td>Jul</td>
<td>Aug</td>
<td>Sep</td>
<td>Oct</td>
<td>Nov</td>
<td>Dec</td>
</tr>
<tr>
<td>2006</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td>23</td>
<td>20</td>
<td>22</td>
<td>19</td>
<td>20</td>
</tr>
<tr>
<td>2007</td>
<td>21</td>
<td>20</td>
<td>22</td>
<td>21</td>
<td>22</td>
<td>21</td>
<td>21 </td>
<td>23</td>
<td>19</td>
<td>23</td>
<td>19</td>
<td>20</td>
</tr>
<tr>
<td>2008</td>
<td>21</td>
<td>21</td>
<td>21</td>
<td>22</td>
<td>21</td>
<td>21</td>
<td>22 </td>
<td>21</td>
<td>21</td>
<td>23</td>
<td>17</td>
<td>22</td>
</tr>
<tr>
<td>2009</td>
<td>20</td>
<td>20</td>
<td>22</td>
<td>22</td>
<td>20</td>
<td>22</td>
<td>22 </td>
<td>21</td>
<td>21</td>
<td>22</td>
<td>18</td>
<td> </td>
</tr>
</table>
<p>There are 1218 days in the 40 months. The divorce counts are adjusted to reflect the number of days that the county offices are open. </p>
<h2>Plotting the Data Sets</h2>
<p>Since the dependent variable is a time series, one could expect autocorrelation in the error terms which may need to be taken into account. Below, I have plotted the adjusted divorce counts and the jump point variable.</p>
<p>Next plot the two data vectors:</p>
<pre>
data.d.v = cbind(
&quot;jump point variable&quot;=vulcan.ts, 
&quot;adjusted divorce count&quot;=div.a.ts)
plot(data.d.v, main=&quot;
Adjusted Divorce Counts in Iowa with the Jump Point Variable
August 2006 to November 2009&quot;)</pre>
<p>Here is the plot:<br>
<a title="" data-rel="nofollow lightbox-0" target="_blank" rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2016/10/ts-div-vulc.jpeg?ssl=1"><img sizes="(max-width: 756px) 100vw, 756px" alt="time series plots of divorce counts and the jump point variable" class="wp-image-4844" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2016/10/ts-div-vulc.jpeg?resize=456%2C324&ssl=1" data-recalc-dims="1"></a></p>
<p>A relationship between the two plots is not immediately evident. Therefore, in the second part we will evaluate the associations by fitting a regression model.</p>
<ul></ul>
<p><strong>
<p>Related Post</p>
<p>
<ol>
<li><a title="Permanent Link toLinear Regression from Scratch in R" target="_blank" rel="nofollow" href="https://datascienceplus.com/linear-regression-from-scratch-in-r/">Linear Regression from Scratch in R</a></li>
<li><a title="Permanent Link toR for Publication by Page Piccinini: Lesson 5 – Analysis of Variance (ANOVA)" target="_blank" rel="nofollow" href="https://datascienceplus.com/r-for-publication-by-page-piccinini-lesson-5-analysis-of-variance-anova/">R for Publication by Page Piccinini: Lesson 5 – Analysis of Variance (ANOVA)</a></li>
<li><a title="Permanent Link toR for Publication by Page Piccinini: Lesson 4 – Multiple Regression" target="_blank" rel="nofollow" href="https://datascienceplus.com/r-for-publication-by-page-piccinini-lesson-4-multiple-regression/">R for Publication by Page Piccinini: Lesson 4 – Multiple Regression</a></li>
<li><a title="Permanent Link toR for Publication by Page Piccinini: Lesson 3 – Logistic Regression" target="_blank" rel="nofollow" href="https://datascienceplus.com/r-for-publication-by-page-piccinini-lesson-3-logistic-regression/">R for Publication by Page Piccinini: Lesson 3 – Logistic Regression</a></li>
<li><a title="Permanent Link toR for Publication by Page Piccinini: Lesson 2 – Linear Regression" target="_blank" rel="nofollow" href="https://datascienceplus.com/r-for-publication-by-page-piccinini-lesson-2-linear-regression/">R for Publication by Page Piccinini: Lesson 2 – Linear Regression</a></li>
</ol></strong>
<div>
<a target="_blank" rel="nofollow" href="http://feeds.feedburner.com/~ff/datascienceplus?a=wkI1lvcnNSE:2JX5uuAnvLY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/datascienceplus?i=wkI1lvcnNSE:2JX5uuAnvLY:D7DqB2pKExk" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.feedburner.com/~ff/datascienceplus?a=wkI1lvcnNSE:2JX5uuAnvLY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=qj6IDK7rITs" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.feedburner.com/~ff/datascienceplus?a=wkI1lvcnNSE:2JX5uuAnvLY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=yIl2AUoC8zA" border="0"></a>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://datascienceplus.com/fitting-a-simple-regression-model-with-auto-correlated-errors-an-astrological-example-part-1-the-data/"> DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/iAvrIgvNB0g"></a></div>