-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdirectionalData-pandoc.html
More file actions
332 lines (332 loc) · 22.1 KB
/
directionalData-pandoc.html
File metadata and controls
332 lines (332 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<h1>Introduction</h1>
<h2>Examples</h2>
<p>Wish to analyze data in which response is a "direction":</p>
<ul>
<li>2d directional data are called <em>circular</em> data</li>
<li>3d directional data are called <em>spherical</em> data</li>
<li>not all "directional" data are directions in the usual sense</li>
<li>"directional" data may also arise in higher dimensions</li>
</ul>
<h2>Wind Directions</h2>
<ul>
<li>Recorded at Col de la Roa, Italian Alps</li>
<li>n = 310 (first 40 listed below)</li>
<li>Radians, clockwise from north</li>
<li>Source: Agostinelli (CSDA 2007); also R package <code>circular</code></li>
</ul>
<h3>Data</h3>
<pre><code>ascii(matrix(wind[1:40], ncol=5, byrow=TRUE), digits=2,
include.rownames=FALSE, include.colnames=FALSE)
</code></pre>
<h3>Plot</h3>
<pre id="windDataPlot"><code>require("circular")
par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(windc, cex=1.5, axes=FALSE,
bin=360, stack=TRUE, sep=0.035, shrink=1.3)
axis.circular(at=circular(seq(0, (7/4)*pi, pi/4),
template="geographics"),
labels=c("N","NE","E","SE","S","SW","W","NW"),
cex=1.4)
ticks.circular(circular(seq(0, (15/8)*pi, pi/8)),
zero=pi/2, rotation="clock",
tcl=0.075)
</code></pre>
<p><img src="file:Plots/wind.png" alt="" /></p>
<h2>Arrival Times at an ICU</h2>
<ul>
<li>24-hour clock times (format <code>hrs.mins</code>)</li>
<li>n = 254 (first 32 listed below)</li>
<li>Source: Cox & Lewis (1966); also Fisher (1993) and R package <code>circular</code></li>
</ul>
<h3>Data</h3>
<pre><code>ascii(matrix(fisherB1[1:32], ncol=4, byrow=TRUE), digits=2,
include.rownames=FALSE, include.colnames=FALSE)
</code></pre>
<h3>Plot</h3>
<pre id="icuDataPlot"><code>## Note that pch=17 does not work properly here.
par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(fisherB1c, cex=1.5, axes=TRUE,
bin=360, stack=TRUE, sep=0.035, shrink=1.3)
</code></pre>
<p><img src="file:Plots/icu.png" alt="" /></p>
<h2>Primate Vertebrae</h2>
<ul>
<li>Orientation of left superior facet of last lumbar vertebra in humans, gorillas, and chimpanzees</li>
<li>Source: Keifer (2005 UF Anthropology MA Thesis)</li>
</ul>
<p><img src="file:Pictures/Gray93.png" alt="as superior articulate process." /></p>
<h2>Plot of Human Data</h2>
<p><img src="file:Pictures/vertebraeOnSphere.png" alt="chimpanzees (red), 16 gorillas (green) and 19 humans (blue)." /></p>
<h2>Butterfly Migrations</h2>
<ul>
<li>Direction of travel observed for 2649 migrating butterflies in Florida</li>
<li>Source: Thomas J Walker, University of Florida, Dept of Entomology and Nematology</li>
<li>Other variables:
<ul>
<li>site: 23 locations in Florida</li>
<li>observer: Thomas Walker (tw) or James J. Whitesell (jw)</li>
<li>species: cloudless sulphur (cs), gulf fritillary (gf), long-tailed skipper (lt)</li>
<li>distance to coast (km)</li>
<li>date and time of observation</li>
<li>percentage of sky free of clouds</li>
<li>quality of sunlight: (b)right, (h)aze, (o)bstructed, (p)artly obstructed</li>
<li>presence/absence and direction (N, NE, E, SE, S, SW, W, NW) of wind</li>
<li>temperature</li>
</ul></li>
</ul>
<h2>Why is the Analysis of Directional Data Different?</h2>
<ul>
<li>First three observations from the wind directions data: <code class="sourceCode r" rundoc-language="R"><span class="kw">paste</span>(<span class="kw">round</span>(wind[<span class="dv">1</span>:<span class="dv">3</span>], <span class="dv">2</span>), <span class="dt">collapse=</span><span class="st">", "</span>)</code></li>
<li>The mean of these three numbers is <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(<span class="kw">mean</span>(wind[<span class="dv">1</span>:<span class="dv">3</span>]), <span class="dv">2</span>)</code> {{{results(<code>2.47</code>)}}}</li>
<li>What do you think?</li>
</ul>
<pre id="meanAnglePlot"><code>par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(windc[1:3], cex=2, lwd=1.5, axes=TRUE, ticks=TRUE, tcl=0.05)
points(circular(mean(wind[1:3]), units="radians", template="geographics"),
pch=8, cex=4)
</code></pre>
<p><img src="file:Plots/meanAngle.png" alt="" /></p>
<h1>Graphical Display of Directional Data</h1>
<h2>Graphical Display of Circular Data (in R)</h2>
<ul>
<li>Have already seen simple dot plots for circular data, e.g., for the wind data:</li>
</ul>
<div class="sourceCode" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><<span class="er"><</span>windConvert><span class="er">></span>
<span class="er"><<</span>windDataPlot><span class="er">></span></code></pre></div>
<h2>Graphical Display of Circular Data (in R) (ctd)</h2>
<ul>
<li>and for the ICU data:</li>
</ul>
<div class="sourceCode" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><<span class="er"><</span>icuDataPlot><span class="er">></span></code></pre></div>
<ul>
<li>and one more ...</li>
</ul>
<h2>Graphical Display of Circular Data (in R) (ctd)</h2>
<pre id="antsDataPlot"><code>par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(fisherB10c$set1, units="degrees", zero=pi/2,
rotation="clock", pch=16, cex=1.5)
ticks.circular(circular(seq(0, (11/6)*pi, pi/6)),
zero=pi/2, rotation="clock", tcl=0.075)
points(fisherB10c$set2, zero=pi/2,
rotation="clock", pch=16, col="darkgrey",
next.points=-0.1, cex=1.5)
points(fisherB10c$set3, zero=pi/2,
rotation="clock", pch=1,
next.points=0.1, cex=1.5)
</code></pre>
<p><img src="file:Plots/ants.png" alt="three different experimental conditions:" /></p>
<h2>Graphical Display of Circular Data (in R) (ctd)</h2>
<div class="sourceCode" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><<span class="er"><</span>antsDataPlot><span class="er">></span></code></pre></div>
<h2>Circular Histograms</h2>
<ul>
<li><a href="https://www.google.com/search?q=R+circular+histogram">Circular histograms</a> exist (see Fisher and Mardia and Jupp) but is there a ready-made function in R?</li>
</ul>
<h2>Rose Diagrams</h2>
<ul>
<li>Invented by <a href="https://en.wikipedia.org/wiki/Florence_Nightingale">Florence Nightingale</a> (elected first female member of the Royals Statistical Society in 1859; honorary member of ASA)</li>
<li><a href="https://github.com/jennybc/r-graph-catalog/tree/master/figures/fig05-14_nightingale-data">Nightingale's rose in R</a> (see also <a href="http://www.r-bloggers.com/going-beyond-florence-nightingales-data-diagram-did-flo-blow-it-with-wedges/">this post</a> and the <a href="http://shiny.stat.ubc.ca/r-graph-catalog/">R graph catalog</a>)</li>
<li>Note that radii of segments are proportional to <em>square root</em> of the frequencies (counts), so that areas are proportional to frequencies. Is this the right thing to do?</li>
<li>Rose diagrams suffer from the same problems as histograms. The impression conveyed may depend strongly on:
<ul>
<li>the binwidth of the cells</li>
<li>the choice of starting point for the bins</li>
</ul></li>
</ul>
<h2>Adding a Rose Diagram to the Plot of Wind Directions</h2>
<div class="sourceCode" id="windRosePart" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><span class="kw">rose.diag</span>(windc, <span class="dt">bins=</span><span class="dv">16</span>, <span class="dt">col=</span><span class="st">"darkgrey"</span>,
<span class="dt">cex=</span><span class="fl">1.5</span>, <span class="dt">prop=</span><span class="fl">1.35</span>, <span class="dt">add=</span><span class="ot">TRUE</span>)</code></pre></div>
<h2>Adding a Rose Diagram to the Plot of Wind Directions</h2>
<pre id="windRose"><code><<windDataPlot>>
<<windRosePart>>
</code></pre>
<p><img src="file:Plots/windRose.png" alt="(segment radii are proportional to square roots of counts)." /></p>
<h2>Changing the Binwidth</h2>
<h3>Fewer/Wider Bins</h3>
<pre id="windRoseWideBins"><code><<windDataPlot>>
<<windRoseWideBinsPart>>
</code></pre>
<p><img src="file:Plots/windRoseWide.png" alt="" /></p>
<h3>Narrow Bins</h3>
<pre id="windRoseNarrowBins"><code><<windDataPlot>>
<<windRoseNarrowBinsPart>>
</code></pre>
<p><img src="file:Plots/windRoseNarrow.png" alt="" /></p>
<h2>Changing the Radii</h2>
<ul>
<li>I think that the default "radii proportional to counts" is generally best, but this is not always obvious. The scale certainly makes a big difference however.</li>
</ul>
<div class="sourceCode" id="windRoseLinearPart" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><span class="kw">rose.diag</span>(windc, <span class="dt">bins=</span><span class="dv">16</span>, <span class="dt">col=</span><span class="st">"darkgrey"</span>,
<span class="dt">radii.scale=</span><span class="st">"linear"</span>,
<span class="dt">cex=</span><span class="fl">1.5</span>, <span class="dt">prop=</span><span class="fl">2.4</span>, <span class="dt">add=</span><span class="ot">TRUE</span>)</code></pre></div>
<h2>Changing the Radii</h2>
<pre id="windRoseLinear"><code><<windDataPlot>>
<<windRoseLinearPart>>
</code></pre>
<p><img src="file:Plots/windRoseLinear.png" alt="(segment radii proportional to counts)." /></p>
<h2>Kernel Density Estimates</h2>
<div class="sourceCode" id="windKdensPart" rundoc-language="R" rundoc-exports="code" rundoc-eval="no"><pre class="sourceCode r rundoc-block"><code class="sourceCode r"><span class="kw">lines</span>(<span class="kw">density.circular</span>(windc, <span class="dt">bw=</span><span class="dv">40</span>), <span class="dt">lwd=</span><span class="dv">2</span>, <span class="dt">lty=</span><span class="dv">1</span>)</code></pre></div>
<h2>Kernel Density Estimates</h2>
<pre id="windKdens"><code>par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(windc, cex=1.5, axes=FALSE,
bin=360, stack=TRUE, sep=0.035, shrink=1.7)
axis.circular(at=circular(seq(0, (7/4)*pi, pi/4),
template="geographics"),
labels=c("N","NE","E","SE","S","SW","W","NW"),
cex=1.4)
ticks.circular(circular(seq(0, (15/8)*pi, pi/8)),
## zero=pi/2, rotation="clock",
tcl=0.075)
<<windRosePart>>
<<windKdensPart>>
</code></pre>
<p><img src="file:Plots/windKdens.png" alt="and kernel density estimate." /></p>
<h2>Spherical Data</h2>
<ul>
<li>Are there any canned routines for plotting spherical data in R?</li>
</ul>
<h1>Basic Summary Statistics</h1>
<h2>Mean Direction and Mean Resultant Length</h2>
<ul>
<li>First three observations from the wind directions data:</li>
</ul>
<pre><code>theta <- wind[1:3]
x <- sin(theta)
y <- cos(theta)
ascii(cbind(theta, x, y), digits=2,
include.rownames=FALSE, include.colnames=TRUE)
</code></pre>
<ul>
<li><p>resultant (sum of direction vectors): (<code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(xsum, <span class="dv">3</span>)</code>, <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(ysum, <span class="dv">3</span>)</code>)</p></li>
<li><p>mean vector: <span class="math inline">$(\bar{x}, \bar{y}) = $</span> (<code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(xbar, <span class="dv">3</span>)</code>, <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(ybar, <span class="dv">3</span>)</code>)</p></li>
<li><p>resultant length (Euclidean norm of resultant): R = <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(resultantLength, <span class="dv">3</span>)</code></p></li>
<li><p>mean resultant length: <span class="math inline">$\bar{R} = $</span> <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(meanResultantLength, <span class="dv">3</span>)</code></p></li>
<li><p>mean direction: <span class="math inline">$(\bar{x}, \bar{y})/\bar{R} = $</span> (<code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(meanDirection[<span class="dv">1</span>], <span class="dv">3</span>)</code>, <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(meanDirection[<span class="dv">2</span>], <span class="dv">3</span>)</code>)</p></li>
<li><p><span class="math inline">$\tilde{\theta} = $</span> <code class="sourceCode r" rundoc-language="R"><span class="kw">round</span>(meanDirectionRadians, <span class="dv">3</span>)</code></p></li>
</ul>
<h2>Plot</h2>
<pre id="meanDirection"><code>par(mar=c(0,0,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plot(windc[1:3], cex=2, lwd=1.5, axes=TRUE, ticks=TRUE, tcl=0.05)
points(circular(meanDirectionRadians, units="radians", template="geographics"),
pch=8, cex=4)
</code></pre>
<p><img src="file:Plots/meanDirection.png" alt="and their sample mean direction." /></p>
<h1>Aside: Generating from the Uniform Distribution on the Sphere</h1>
<h2>Generating Random Points on the Sphere</h2>
<ul>
<li>Wish to generate a random "direction" in d-dimensions; i.e., an observation from the uniform distribution in the <span class="math inline"><em>d</em> − 1</span> sphere.</li>
<li>Usual way: let X ∼ N<sub>d</sub>(0, I) and return U = X/||X||.</li>
<li>An alternative rejection sampler:
<ul>
<li>Repeat until ||X|| <= 1
<ul>
<li>Let X be uniformly distributed on the cube [-1,1]<sup>d</sup></li>
</ul></li>
<li>Return U = X/||X||</li>
</ul></li>
<li>What is the acceptance rate for the rejection sampler:
<ul>
<li>Volume of the <span class="math inline"><em>d</em> − 1</span> sphere is <span class="math inline"><em>π</em><sup><em>d</em>/2</sup>/Γ(<em>d</em>/2 + 1)</span></li>
<li>Volume of [-1,1]<sup>d</sup> is 2<sup>d</sup></li>
<li>Acceptance rate is <span class="math inline">(<em>π</em><sup>1/2</sup>/2)<sup><em>d</em></sup>/Γ(<em>d</em>/2 + 1)</span></li>
<li>Curse of dimensionality</li>
</ul></li>
</ul>
<pre><code>accRate <- function(d) ((sqrt(pi)/2)^d)/gamma(d/2 + 1)
d <- 2:10
## ar <- matrix(accRate(d), nrow=1,
## dimnames=list("accept rate", "d"=d))
ar <- rbind("dimension"=d, "accept rate (%)"= 100*accRate(d))
ascii(ar, digits=0, include.rownames=TRUE, include.colnames=FALSE)
</code></pre>
<h2>Code for Timing Results</h2>
<div class="sourceCode" id="runifSphereR" rundoc-language="R" rundoc-exports="code"><pre class="sourceCode r rundoc-block"><code class="sourceCode r">runifSphere <-<span class="st"> </span>function(n, dimension, <span class="dt">method=</span><span class="kw">c</span>(<span class="st">"norm"</span>, <span class="st">"cube"</span>, <span class="st">"slownorm"</span>)) {
method <-<span class="st"> </span><span class="kw">match.arg</span>(method)
if (method==<span class="st">"norm"</span>) {
u <-<span class="st"> </span><span class="kw">matrix</span>(<span class="kw">rnorm</span>(n*dimension), <span class="dt">ncol=</span>dimension)
u <-<span class="st"> </span><span class="kw">sweep</span>(u, <span class="dv">1</span>, <span class="kw">sqrt</span>(<span class="kw">apply</span>(u*u, <span class="dv">1</span>, sum)), <span class="st">"/"</span>)
} else if (method==<span class="st">"slownorm"</span>) {
u <-<span class="st"> </span><span class="kw">matrix</span>(<span class="dt">nrow=</span>n, <span class="dt">ncol=</span>dimension)
for (i in <span class="dv">1</span>:n) {
x <-<span class="st"> </span><span class="kw">rnorm</span>(dimension)
xnorm <-<span class="st"> </span><span class="kw">sqrt</span>(<span class="kw">sum</span>(x^<span class="dv">2</span>))
u[i,] <-<span class="st"> </span>x/xnorm
}
} else {
u <-<span class="st"> </span><span class="kw">matrix</span>(<span class="dt">nrow=</span>n, <span class="dt">ncol=</span>dimension)
for (i in <span class="dv">1</span>:n) {
x <-<span class="st"> </span><span class="kw">runif</span>(dimension, -<span class="dv">1</span>, <span class="dv">1</span>)
xnorm <-<span class="st"> </span><span class="kw">sqrt</span>(<span class="kw">sum</span>(x^<span class="dv">2</span>))
while (xnorm ><span class="st"> </span><span class="dv">1</span>) {
x <-<span class="st"> </span><span class="kw">runif</span>(dimension, -<span class="dv">1</span>, <span class="dv">1</span>)
xnorm <-<span class="st"> </span><span class="kw">sqrt</span>(<span class="kw">sum</span>(x^<span class="dv">2</span>))
}
u[i,] <-<span class="st"> </span>x/xnorm
}
}
u
}</code></pre></div>
<h2>Easy fix for Borel's paradox in 3-d</h2>
<p>Take longitude <span class="math inline"><em>ϕ</em> ∼ <em>U</em>(0, 2<em>π</em>)</span> independent of latitude <span class="math inline"><em>θ</em> = arcsin(2<em>U</em> − 1)</span>, <span class="math inline"><em>U</em> ∼ <em>U</em>(0, 1)</span>.</p>
<h1>Rotationally Symmetric Distributions</h1>
<h2>Comparison of Projected Normal and Langevin Distributions</h2>
<p>One way that we might compare the <span class="math inline">$\nlangevin(\mu, \kappa)$</span> and <span class="math inline">$\npn(\gamma\mu, I)$</span> distributions by choosing <em>κ</em>and <em>γ</em>to give the same mean resultant lengths and comparing the densities of the cosine of the angle <em>θ</em>between <span class="math inline"><em>U</em></span> and <span class="math inline"><em>μ</em></span>.</p>
<p>Of course matching mean resultant lengths is not necessarily the best way to compare these families of distributions.</p>
<h2><span class="math inline"><em>d</em> = 2</span></h2>
<pre id="PNvLvMF2"><code>par(mar=c(2,2,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plotPNvLvMF(2)
</code></pre>
<p><img src="file:Plots/PNvLvMF2.png" alt="" /></p>
<h2><span class="math inline"><em>d</em> = 3</span></h2>
<pre id="PNvLvMF3"><code>par(mar=c(2,2,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plotPNvLvMF(3)
</code></pre>
<p><img src="file:Plots/PNvLvMF3.png" alt="" /></p>
<h2><span class="math inline"><em>d</em> = 4</span></h2>
<pre id="PNvLvMF4"><code>par(mar=c(2,2,0,0)+0.1, oma=c(0,0,0,0)+0.1)
plotPNvLvMF(4)
</code></pre>
<p><img src="file:Plots/PNvLvMF4.png" alt="" /></p>
<h1>Regression</h1>
<h2>Gould's Model</h2>
<p>A.k.a., the <a href="https://commons.wikimedia.org/wiki/File:Barber-pole-01.gif#">barber pole</a> model.</p>
<h2>Gould's Model: Likelihood</h2>
<p>Calculate the (profile) log-likelihood for Gould (1969 Biometrics) model for simple (single predictor) regression with an intercept. For fixed "slope" <em>β</em>, this function "profiles out" (maximizes over) the "intercept" term and optionally the concentration parameter <em>κ</em>.</p>
<div class="sourceCode" rundoc-language="R" rundoc-exports="code"><pre class="sourceCode r rundoc-block"><code class="sourceCode r">loglklhd.gould <-<span class="st"> </span>function(beta, theta, x, <span class="dt">do.kappa=</span><span class="ot">FALSE</span>) {
res <-<span class="st"> </span><span class="kw">sapply</span>(beta,
function(b, th, x) {
<span class="kw">sqrt</span>(<span class="kw">sum</span>(<span class="kw">cos</span>(th -<span class="st"> </span>b*x))^<span class="dv">2</span>
+<span class="st"> </span><span class="kw">sum</span>(<span class="kw">sin</span>(th -<span class="st"> </span>b*x))^<span class="dv">2</span>)
},
<span class="dt">th=</span>theta, <span class="dt">x=</span>x)
if (do.kappa) {
n <-<span class="st"> </span><span class="kw">length</span>(theta)
kappa <-<span class="st"> </span><span class="kw">sapply</span>(res/n, imrlLvMF, <span class="dt">dimen=</span><span class="dv">2</span>)
res <-<span class="st"> </span>n*<span class="kw">log</span>(<span class="kw">constLvMF</span>(kappa, <span class="dt">dimen=</span><span class="dv">2</span>)) +<span class="st"> </span>kappa*res
}
res
}</code></pre></div>
<h2>Gould's Model with Equally Spaced X</h2>
<pre id="gouldLatticeXPlot1"><code><<gouldLatticeXData>>
<<gouldPlot>>
</code></pre>
<pre id="gouldLatticeXPlot2"><code><<gouldPlot>>
</code></pre>
<h2>Gould's Model with Equally-Spaced X: Kappa Not Profiled Out</h2>
<p><img src="file:Plots/gouldLatticeX1.png" alt="κnot profiled out." /></p>
<h2>Gould's Model with Equally-Spaced X: Kappa Profiled Out</h2>
<p><img src="file:Plots/gouldLatticeX2.png" alt="κprofiled out." /></p>
<h2>Gould's Model with Random X: Data Generation</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">alpha <-<span class="st"> </span><span class="dv">0</span>
beta <-<span class="st"> </span><span class="dv">1</span>
kappa =<span class="st"> </span><span class="fl">2.5</span>
x <-<span class="st"> </span><span class="kw">rnorm</span>(<span class="dv">10</span>)
mu <-<span class="st"> </span><span class="kw">as.circular</span>((alpha +<span class="st"> </span>beta*x) %%<span class="st"> </span>(<span class="dv">2</span>*pi))
theta <-<span class="st"> </span><span class="kw">as.circular</span>(mu +<span class="st"> </span><span class="kw">rvonmises</span>(<span class="kw">length</span>(mu), <span class="dt">mu=</span><span class="dv">0</span>, <span class="dt">kappa=</span>kappa))</code></pre></div>
<pre id="gouldRandomXPlot1"><code><<gouldPlot>>
</code></pre>
<pre id="gouldRandomXPlot2"><code><<gouldPlot>>
</code></pre>
<h2>Gould's Model with Random X: Kappa Not Profiled Out</h2>
<p><img src="file:Plots/gouldRandomX1.png" alt="κnot profiled out." /></p>
<h2>Gould's Model with Random X: Kappa Profiled Out</h2>
<p><img src="file:Plots/gouldRandomX2.png" alt="κprofiled out." /></p>