Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Poppy Miller
sourceR
Commits
50ffc6c3
Commit
50ffc6c3
authored
Apr 12, 2017
by
Chris Jewell
Browse files
Added test for mismatched data.
parent
8ab72778
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/testthat/testHaldDPTimeLoc.R
View file @
50ffc6c3
# Test time/location data structure
test_that
(
"Test time/location data structures"
,
{
testdata
=
function
()
{
# Test priors
priors
<-
list
(
...
...
@@ -14,7 +15,6 @@ test_that("Test time/location data structures", {
ss
=
group_by
(
sim_SA_data
,
Time
,
Location
)
%>%
slice
(
1
:
10
)
%>%
ungroup
%>%
as.data.frame
src
=
reshape2
::
melt
(
ss
[
ss
$
Location
==
'A'
,
c
(
1
,
2
:
9
)],
id.vars
=
c
(
'Type'
,
'Time'
),
...
...
@@ -29,14 +29,35 @@ test_that("Test time/location data structures", {
variable.name
=
'Source'
,
value.name
=
'Count'
)
y
=
Y
(
data
=
ss
,
y
=
'Human'
,
type
=
'Type'
,
time
=
'Time'
,
location
=
'Location'
)
x
=
X
(
data
=
src
,
x
=
'Count'
,
type
=
'Type'
,
time
=
'Time'
,
source
=
'Source'
)
k
=
Prev
(
sim_SA_prev
,
prev
=
'Value'
,
time
=
'Time'
,
source
=
'Source'
)
list
(
y
=
ss
[,
c
(
'Human'
,
'Type'
,
'Time'
,
'Location'
)],
X
=
src
,
prior
=
priors
,
prev
=
sim_SA_prev
)
}
test_that
(
"Detect y/X data mismatch"
,
{
dat
=
testdata
()
y
=
Y
(
data
=
dat
$
y
,
y
=
'Human'
,
type
=
'Type'
,
time
=
'Time'
,
location
=
'Location'
)
x
=
X
(
data
=
dat
$
X
,
x
=
'Count'
,
type
=
'Type'
,
time
=
'Time'
,
source
=
'Source'
)
k
=
Prev
(
dat
$
prev
,
prev
=
'Value'
,
time
=
'Time'
,
source
=
'Source'
)
expect_silent
(
HaldDP
(
y
=
y
,
x
=
x
,
k
=
k
,
priors
=
dat
$
prior
,
a_q
=
0.1
))
dat
$
X
=
dat
$
X
[
dat
$
X
$
Time
==
'1'
,]
x
=
X
(
data
=
dat
$
X
,
x
=
'Count'
,
type
=
'Type'
,
time
=
'Time'
,
source
=
'Source'
)
expect_error
(
HaldDP
(
y
=
y
,
x
=
x
,
k
=
k
,
priors
=
dat
$
prior
,
a_q
=
0.1
),
"Times in x and y do not match"
)
})
test_that
(
"Test time/location data structures"
,
{
dat
=
testdata
()
y
=
Y
(
data
=
dat
$
y
,
y
=
'Human'
,
type
=
'Type'
,
time
=
'Time'
,
location
=
'Location'
)
x
=
X
(
data
=
dat
$
X
,
x
=
'Count'
,
type
=
'Type'
,
time
=
'Time'
,
source
=
'Source'
)
k
=
Prev
(
dat
$
prev
,
prev
=
'Value'
,
time
=
'Time'
,
source
=
'Source'
)
model
=
HaldDP
(
y
=
y
,
x
=
x
,
k
=
k
,
priors
=
prior
s
,
priors
=
dat
$
prior
,
a_q
=
0.1
)
model
$
mcmc_params
(
n_iter
=
100
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment