In [54]:
import statsmodels.api

In [69]:
import pathlib
import json
import geojson
import datashader
import pandas
import toolz
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

In [4]:
f = pathlib.Path('/Users/baart_f/data/BOX061_transects_rates.json')

In [16]:
data = geojson.load(f.open())

In [ ]:
feature = data['features'][0]
records = []
for feature in data['features']:
    # fold
    record = toolz.merge(*toolz.get(['properties', 'geometry'], feature))
    records.append(record)
df = pandas.DataFrame(records)

In [71]:
record = df.iloc[1]
_ = plt.plot(record['dt'], record['distances'], 'k.')
_ = plt.plot(np.array(record['dt'])[record['outliers']], np.array(record['distances'])[record['outliers']], 'r.')
record


Out[71]:
RMSE                                                                     17.453
b_unc                                                                       7.6
change_rate                                                                -0.4
change_rate_unc                                                             0.4
coordinates                   [[115.67817480305608, -34.47973884802565], [11...
country_id                                                                  AUS
country_name                                                          Australia
distances                     [869.3256292927762, 865.4742744561033, 880.876...
dt                            [29.002648925, 4.00008213721, 17.0024025134, 2...
flag_ok                                                                    True
flag_sandy                                                                False
intercept                                                                 878.5
intersection_10.0015742965          [[115.67302099535196, -34.484506327567665]]
intersection_11.0009103541          [[115.67286891816565, -34.484647000946886]]
intersection_12.0002464116           [[115.67291832013386, -34.48460130350849]]
intersection_13.0023203762           [[115.67314150751872, -34.48439485207438]]
intersection_14.0016564337           [[115.6730535495047, -34.484476214521294]]
intersection_15.0009924913          [[115.67286232397255, -34.484653100656104]]
intersection_16.0003285488           [[115.67297683735318, -34.48454717431647]]
intersection_17.0024025134          [[115.67291036582714, -34.484608661343394]]
intersection_18.0017385709          [[115.67281976310385, -34.484692469968934]]
intersection_19.0010746285           [[115.67290015516656, -34.48461810633333]]
intersection_2.00141002211                                                  NaN
intersection_20.0004106861           [[115.67316239150423, -34.48437553407125]]
intersection_21.0024846506           [[115.67313141390031, -34.48440418882279]]
intersection_22.0018207082            [[115.67300110017784, -34.4845247308765]]
intersection_23.0011567657           [[115.67284495784891, -34.48466916453051]]
intersection_24.0004928233          [[115.67317414059615, -34.484364665981225]]
intersection_25.0025667878           [[115.67284361564742, -34.48467040608298]]
intersection_26.0019028454           [[115.67286570068137, -34.48464997715922]]
intersection_27.0012389029           [[115.67298280586644, -34.48454165336177]]
intersection_28.0005749605           [[115.67294482689645, -34.48457678441132]]
intersection_29.002648925            [[115.67297940068961, -34.48454480319595]]
intersection_3.00074607966          [[115.67274683314729, -34.484759931008256]]
intersection_30.0019849826           [[115.67307941828575, -34.48445228552945]]
intersection_31.0013210401             [[115.672689459175, -34.48481300254685]]
intersection_32.0006570977            [[115.6729366173543, -34.48458437834444]]
intersection_4.00008213721           [[115.67300241777018, -34.48452351208563]]
intersection_5.00215610177            [[115.6728835125379, -34.48463350097267]]
intersection_6.00149215932          [[115.67302772425089, -34.484500103242965]]
intersection_7.00082821687           [[115.67292615651316, -34.48459405475734]]
intersection_8.00016427442           [[115.67289189808466, -34.48462574423757]]
intersection_9.00223823898           [[115.67299916263718, -34.48452652312794]]
outliers                                                                   [16]
transect_id                                                       BOX_061_011_1
transect_origin                        [115.67817480305608, -34.47973884802565]
type                                                                 LineString
Name: 1, dtype: object

In [73]:
y = np.array(record['distances'])
y[record['outliers']] = None
model = statsmodels.api.OLS(y, statsmodels.api.add_constant(record['dt']), missing='drop')
fit = model.fit()
fit.summary()


Out[73]:
OLS Regression Results
Dep. Variable: y R-squared: 0.030
Model: OLS Adj. R-squared: -0.006
Method: Least Squares F-statistic: 0.8434
Date: Thu, 20 Apr 2017 Prob (F-statistic): 0.367
Time: 09:55:10 Log-Likelihood: -124.08
No. Observations: 29 AIC: 252.2
Df Residuals: 27 BIC: 254.9
Df Model: 1
Covariance Type: nonrobust
coef std err t P>|t| [95.0% Conf. Int.]
const 878.4805 7.576 115.956 0.000 862.936 894.025
x1 -0.3661 0.399 -0.918 0.367 -1.184 0.452
Omnibus: 1.455 Durbin-Watson: 2.021
Prob(Omnibus): 0.483 Jarque-Bera (JB): 1.247
Skew: -0.340 Prob(JB): 0.536
Kurtosis: 2.245 Cond. No. 43.0

In [ ]: