I will keep trying to debug this on my own, but I'm not a great R programmer and it's hard to tell if this is an issue in the surveillance
package or how I am constructing data or something else.
So while I will keep trying to troubleshoot this, a few questions if there are any thoughts:
E rpy2.rinterface.RRuntimeError: Error in algo.farrington.data.glm(dayToConsider = dayToConsider, b = control$b, :
E Some reference values did not exist (index<1).
import pandas as pd
import pytest
from epysurv.models.timepoint import FarringtonFlexible
def test_farrington_weekly_example():
model = FarringtonFlexible()
total_periods = 100
test_size = 20
case_count = 10
# set up some weekly data
dates = pd.date_range('2017-07-09', periods=total_periods, freq='7D')
# just make this constant (but this also fails with random or real case count values)
case_counts = [case_count] * total_periods
df = pd.DataFrame({'n_cases': case_counts}, index = dates)
train_data = df[:-1 * test_size]
test_data = df[-1 * test_size:]
# make sure we can fit and predict
model.fit(train_data)
_ = model.predict(test_data)
def test_farrington_weekly_example():
model = FarringtonFlexible()
total_periods = 100
test_size = 20
case_count = 10
# set up some weekly data
dates = pd.date_range('2017-07-09', periods=total_periods, freq='7D')
# just make this constant (but this also fails with random or real case count values)
case_counts = [case_count] * total_periods
df = pd.DataFrame({'n_cases': case_counts}, index = dates)
train_data = df[:-1 * test_size]
test_data = df[-1 * test_size:]
# make sure we can fit and predict
model.fit(train_data)
> _ = model.predict(test_data)
test_farrington_specific_example.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\epysurv\models\timepoint\_base.py:131: in predict
surveillance_result = self._call_surveillance_algo(r_instance, detection_range)
..\epysurv\models\timepoint\farrington.py:166: in _call_surveillance_algo
surv = surveillance.farringtonFlexible(sts, control=control)
C:\anaconda3\envs\epysurv-dev\lib\site-packages\rpy2\robjects\functions.py:178: in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = R object with classes: ('function',) mapped to:
<DocumentedSTFunction - Python:0x000001C714FD1608 / R:0x000001C70F26E4A8>
args = (R object with classes: ('sts',) mapped to:
<RS4 - Python:0x000001C7151F5548 / R:0x000001C70FF061F0>,)
kwargs = {'control': R object with classes: ('list',) mapped to:
<ListVector - Python:0x000001C7152E92C8 / R:0x000001C71400440...ect with classes: ('character',) mapped to:
<StrVector - Python:0x000001C715468C88 / R:0x000001C7149A7E00>
['delta']}
new_args = [R object with classes: ('sts',) mapped to:
<RS4 - Python:0x000001C7151F5548 / R:0x000001C70FF061F0>]
new_kwargs = {'control': R object with classes: ('list',) mapped to:
<ListVector - Python:0x000001C7152E92C8 / R:0x000001C71400440...ect with classes: ('character',) mapped to:
<StrVector - Python:0x000001C715471C88 / R:0x000001C7149A7E00>
['delta']}
k = 'control'
v = R object with classes: ('list',) mapped to:
<ListVector - Python:0x000001C7152E92C8 / R:0x000001C714004408>
[IntVect...ject with classes: ('character',) mapped to:
<StrVector - Python:0x000001C715478F48 / R:0x000001C7149A7E00>
['delta']
def __call__(self, *args, **kwargs):
new_args = [conversion.py2ri(a) for a in args]
new_kwargs = {}
for k, v in kwargs.items():
new_kwargs[k] = conversion.py2ri(v)
> res = super(Function, self).__call__(*new_args, **new_kwargs)
E rpy2.rinterface.RRuntimeError: Error in algo.farrington.data.glm(dayToConsider = dayToConsider, b = control$b, :
E Some reference values did not exist (index<1).