MeanDurUnder: Mean Duration of sojourn under a treshold

Description Usage Arguments Value Author(s) See Also Examples

View source: R/MeanDurUnder.R

Description

Plot the mean duration of sojourn under thresholds for an observed time series and a simulated one with respect to teh empirical cumulative distribution function (cdf). Confidence intervals are plotted too.

Usage

1
MeanDurUnder(data, data.sim, u, alpha = 0.05,col="red",plot=TRUE)

Arguments

data

observed (or reference) time series, array of dimension T*N.samples*1

data.sim

simulated time series, array of dimension T*N.sim*1. N.sim have to be K*N.samples with K large enough (for instance, K=100)

u

vector of thresholds

alpha

1-confidence level for confidence intervals. Default = 0.05

col

color of the lines for simulated data, default is red

plot

statistic are plotted if TRUE (default)

Value

Returns a plot and a list including ..$F : empirical cdf of data for levels u ..$mdu.data : mean duration under levels u for data ..$F.sim : empirical cdf of simulations for levels u ..$mdu.sim : mean duration under levels u for simulations ..$CI : confidence intervals of mean duration under levels u for simulations

Author(s)

Valerie Monbet, valerie.monbet@univ-rennes1.fr

See Also

valid_all.MSAR, MeanDurOver

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data(meteo.data)
data = array(meteo.data$temperature,c(31,41,1)) 
k = 40
T = dim(data)[1]
N.samples = dim(data)[2]
d = dim(data)[3]
M = 2
order = 2
theta.init = init.theta.MSAR(data,M=M,order=order,label="HH")
mod.hh= NULL
mod.hh$theta = theta.init
mod.hh$theta$A = matrix(c(0.40,0.88,-.09,-.13),2,2)
mod.hh$theta$A0 = matrix(c(6.75,1.08),2,1)
mod.hh$theta$sigma = matrix(c(1.76,3.40),2,1)
mod.hh$theta$prior = matrix(c(0.37,0.63),2,1)
mod.hh$theta$transmat = matrix(c(0.82,0.09,0.18,0.91),2,2)
B.sim = 20*N.samples
Y0 = array(data[1:2,sample(1:dim(data)[2],B.sim,replace=TRUE),],c(2,B.sim,1))
Y.sim = simule.nh.MSAR(mod.hh$theta,Y0=Y0,T,N.samples=B.sim)
u = seq(min(data),max(data),length.out=30)
MeanDurUnder(data,Y.sim$Y,u)

Example output

$F
 [1] 0.0000000000 0.0007867821 0.0007867821 0.0015735641 0.0023603462
 [6] 0.0023603462 0.0047206924 0.0062942565 0.0078678206 0.0133752950
[11] 0.0243902439 0.0440597954 0.0653029111 0.0826121164 0.1109362707
[16] 0.1518489378 0.1919748230 0.2431156570 0.2981904013 0.3548387097
[21] 0.4256490952 0.4885916601 0.5853658537 0.6837136113 0.7718332022
[26] 0.8497246263 0.9307631786 0.9748229740 0.9905586153 0.9992132179

$mdu.data
 [1]   1.000000   1.000000   1.000000   2.000000   1.500000   1.500000
 [7]   1.500000   1.600000   1.428571   1.416667   1.722222   2.000000
[13]   2.075000   2.441860   2.877551   2.757143   3.012346   3.287234
[19]   3.353982   3.854701   4.434426   4.467626   5.276596   6.163121
[25]   7.785714  11.489362  25.170213  59.000000 125.900000 635.000000

$F.sim
 [1] 0.0000393391 0.0000393391 0.0000393391 0.0001573564 0.0011801731
 [6] 0.0018095987 0.0036191975 0.0053894571 0.0086939418 0.0138473643
[11] 0.0249409913 0.0389850511 0.0608575924 0.0863493312 0.1215578285
[16] 0.1620377655 0.2121164437 0.2661683714 0.3228953580 0.3829661684
[21] 0.4428402832 0.5075137687 0.5791896145 0.6644374508 0.7540912667
[26] 0.8340283242 0.9060188828 0.9537765539 0.9801337530 0.9931549961

$mdu.sim
      [,1] [,2] [,3] [,4] [,5]  [,6]     [,7]     [,8]     [,9]    [,10]
 [1,]    1    1    1    1    1 1.000 1.000000 1.000000 1.500000 1.500000
 [2,]    1    1    1    1    1 1.000 1.500000 1.500000 1.285714 1.200000
 [3,]    1    1    1    1    1 1.000 1.000000 1.333333 1.833333 1.777778
 [4,]    1    1    1    1    1 1.000 1.333333 1.400000 1.625000 2.666667
 [5,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.800000
 [6,]    1    1    1    1    1 1.000 2.000000 1.500000 1.333333 1.500000
 [7,]    1    1    1    1    1 1.000 1.875000 1.875000 1.785714 2.055556
 [8,]    1    1    1    1    1 1.000 1.000000 2.000000 1.333333 1.500000
 [9,]    1    1    1    1    1 1.000 1.400000 1.285714 1.666667 1.500000
[10,]    1    1    1    1    1 1.000 1.500000 1.500000 1.571429 1.545455
[11,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.000000
[12,]    1    1    1    1    1 1.000 1.750000 2.333333 2.250000 2.153846
[13,]    1    1    1    1    1 1.000 1.000000 1.000000 1.250000 1.555556
[14,]    1    1    1    1    1 1.000 1.800000 1.571429 1.666667 1.875000
[15,]    1    1    1    1    1 1.125 2.000000 2.857143 2.900000 2.466667
[16,]    1    1    1    1    1 1.400 2.200000 2.666667 2.111111 1.928571
[17,]    1    1    1    1    1 1.000 1.500000 1.333333 3.000000 2.333333
[18,]    1    1    1    1    1 1.000 1.333333 1.111111 1.500000 1.533333
[19,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.000000
[20,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.125000
         [,11]    [,12]    [,13]    [,14]    [,15]    [,16]    [,17]    [,18]
 [1,] 1.529412 1.677419 2.051282 2.387755 2.302632 2.473118 2.990291 3.537736
 [2,] 1.428571 2.043478 2.057143 2.098039 2.287879 2.780822 2.824176 3.158879
 [3,] 1.764706 1.807692 1.777778 2.185185 2.289855 2.406977 2.770000 3.151786
 [4,] 2.050000 2.074074 2.052632 2.196078 2.711864 2.840000 3.112360 3.547368
 [5,] 1.437500 1.576923 1.714286 2.100000 2.277778 2.485294 2.586957 3.135417
 [6,] 1.444444 1.680000 1.707317 2.058824 2.338235 2.592593 2.923913 3.300971
 [7,] 2.000000 2.166667 2.205128 2.301887 2.710145 2.886364 3.357895 4.021277
 [8,] 1.375000 1.533333 1.843750 2.125000 2.196429 2.457143 2.670330 3.273684
 [9,] 1.588235 1.750000 1.970588 2.060000 2.311475 2.671642 2.892857 3.151515
[10,] 2.000000 1.857143 1.911765 2.019608 2.161765 2.635135 3.023256 3.692308
[11,] 1.333333 1.565217 1.729730 1.823529 1.972222 2.232558 2.758242 3.117647
[12,] 1.923077 1.947368 2.555556 2.741379 3.142857 3.575342 3.833333 4.130435
[13,] 1.615385 1.941176 1.864865 1.942308 2.274194 2.546667 2.744681 3.141509
[14,] 2.000000 2.296296 2.361111 2.312500 2.424242 2.340909 2.656566 3.157407
[15,] 2.076923 2.451613 2.742857 3.282051 2.842105 3.069444 3.255556 3.677083
[16,] 1.677419 2.272727 2.684211 2.518519 2.608696 2.602273 2.939394 3.318182
[17,] 1.625000 2.071429 2.300000 2.322581 2.239130 2.385965 2.465753 2.741573
[18,] 1.615385 2.068966 2.307692 2.260000 2.380952 2.558442 3.011765 3.544444
[19,] 1.200000 1.515152 1.837209 2.120000 2.492063 2.710843 2.939394 3.324324
[20,] 1.217391 1.400000 1.680000 1.904762 2.306667 2.792683 3.566265 3.861702
         [,19]    [,20]    [,21]    [,22]    [,23]    [,24]    [,25]     [,26]
 [1,] 3.894737 4.570175 5.472222 5.963303 6.347826 5.909722 7.808000 10.909091
 [2,] 3.845455 4.587156 5.311927 5.564103 6.465517 6.268657 7.353846  9.377193
 [3,] 3.320611 4.322314 4.785714 5.680328 6.349593 6.624060 8.846847 11.123711
 [4,] 3.849057 4.950000 5.441176 5.500000 5.733871 6.139706 7.263566  8.931624
 [5,] 3.306306 4.093458 4.619469 4.689922 5.328244 5.927536 6.685714  9.113043
 [6,] 3.586207 4.537037 5.166667 5.227642 5.562963 6.328358 7.446154  9.598214
 [7,] 4.219048 4.687500 5.342342 5.573770 6.550847 6.826772 7.793651 10.979798
 [8,] 3.387387 3.913793 4.717949 5.316239 5.609375 6.072993 6.962963  8.616667
 [9,] 3.711538 4.271028 4.598291 5.161290 5.477612 6.064748 7.480315  9.357143
[10,] 4.084211 4.804124 5.134615 5.324561 5.570312 6.036765 7.261538  9.419643
[11,] 3.692308 4.308411 4.898148 5.268908 5.492188 6.469231 7.674603 10.113208
[12,] 4.490196 5.019608 5.327273 5.508333 6.375000 7.024390 8.008197 11.294737
[13,] 3.630631 4.369369 4.743590 5.491379 5.589147 6.000000 7.208955  9.621622
[14,] 3.615385 4.146341 4.867769 5.692308 6.444444 7.151261 7.323077  9.500000
[15,] 3.814815 3.912000 4.733333 5.338710 6.729730 6.959350 8.152542 10.252427
[16,] 3.945946 4.495495 5.061947 5.244094 5.782946 6.085714 7.043796  9.398230
[17,] 2.888889 3.365217 4.114035 4.145985 4.456376 4.929936 6.291667  7.601504
[18,] 3.989474 4.480392 4.828829 5.188034 5.500000 5.617021 6.618705  8.298387
[19,] 3.815126 4.341463 4.968254 5.891667 6.346457 6.900763 9.240741 11.195876
[20,] 4.250000 4.666667 5.423423 6.089286 5.976562 7.031746 8.418803  9.990741
         [,27]    [,28]    [,29]    [,30]
 [1,] 16.55714 27.59091 53.86957 125.8000
 [2,] 16.13889 35.05714 89.57143 210.6667
 [3,] 17.05882 34.82857 73.35294 253.2000
 [4,] 14.03704 31.00000 65.63158 114.5455
 [5,] 16.06944 26.82222 54.04348 125.8000
 [6,] 16.16667 26.47826 65.73684 253.2000
 [7,] 16.58571 32.07895 69.22222 180.2857
 [8,] 12.86364 23.17308 41.20000 157.8750
 [9,] 14.30000 24.48980 51.54167 157.5000
[10,] 15.50667 33.00000 78.18750 210.6667
[11,] 14.07317 29.68293 69.55556 158.0000
[12,] 15.14474 28.13953 59.52381 422.6667
[13,] 14.41250 24.18000 49.76000 140.1111
[14,] 15.48649 27.56818 59.33333  83.8000
[15,] 15.79452 29.00000 65.89474 211.0000
[16,] 15.28000 24.57143 56.59091 140.2222
[17,] 12.12903 22.60377 47.65385 126.0000
[18,] 12.89773 26.17391 65.68421 126.1000
[19,] 16.45070 31.23077 54.08696 180.5714
[20,] 15.64865 28.25581 56.63636 157.7500

$CI
           [,1]       [,2]
 [1,]  1.000000   1.000000
 [2,]  1.000000   1.000000
 [3,]  1.000000   1.000000
 [4,]  1.000000   1.000000
 [5,]  1.000000   1.000000
 [6,]  1.000000   1.269375
 [7,]  1.000000   2.105000
 [8,]  1.000000   2.766667
 [9,]  1.000000   2.952500
[10,]  1.000000   2.571667
[11,]  1.208261   2.064135
[12,]  1.454697   2.377838
[13,]  1.692976   2.715000
[14,]  1.862115   3.025232
[15,]  2.062255   3.000000
[16,]  2.284025   3.335041
[17,]  2.523325   3.706476
[18,]  2.920208   4.078585
[19,]  3.087162   4.376103
[20,]  3.624939   4.986544
[21,]  4.344056   5.457475
[22,]  4.404356   6.029444
[23,]  4.870513   6.644761
[24,]  5.256302   7.094491
[25,]  6.447010   9.053641
[26,]  7.932523  11.247778
[27,] 12.477969  16.834097
[28,] 22.874193  34.948571
[29,] 44.265577  84.164062
[30,] 98.404091 342.170000

$mdu.sim.all
      [,1] [,2] [,3] [,4] [,5]  [,6]     [,7]     [,8]     [,9]    [,10]
 [1,]    1    1    1    1    1 1.000 1.000000 1.000000 1.500000 1.500000
 [2,]    1    1    1    1    1 1.000 1.500000 1.500000 1.285714 1.200000
 [3,]    1    1    1    1    1 1.000 1.000000 1.333333 1.833333 1.777778
 [4,]    1    1    1    1    1 1.000 1.333333 1.400000 1.625000 2.666667
 [5,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.800000
 [6,]    1    1    1    1    1 1.000 2.000000 1.500000 1.333333 1.500000
 [7,]    1    1    1    1    1 1.000 1.875000 1.875000 1.785714 2.055556
 [8,]    1    1    1    1    1 1.000 1.000000 2.000000 1.333333 1.500000
 [9,]    1    1    1    1    1 1.000 1.400000 1.285714 1.666667 1.500000
[10,]    1    1    1    1    1 1.000 1.500000 1.500000 1.571429 1.545455
[11,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.000000
[12,]    1    1    1    1    1 1.000 1.750000 2.333333 2.250000 2.153846
[13,]    1    1    1    1    1 1.000 1.000000 1.000000 1.250000 1.555556
[14,]    1    1    1    1    1 1.000 1.800000 1.571429 1.666667 1.875000
[15,]    1    1    1    1    1 1.125 2.000000 2.857143 2.900000 2.466667
[16,]    1    1    1    1    1 1.400 2.200000 2.666667 2.111111 1.928571
[17,]    1    1    1    1    1 1.000 1.500000 1.333333 3.000000 2.333333
[18,]    1    1    1    1    1 1.000 1.333333 1.111111 1.500000 1.533333
[19,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.000000
[20,]    1    1    1    1    1 1.000 1.000000 1.000000 1.000000 1.125000
         [,11]    [,12]    [,13]    [,14]    [,15]    [,16]    [,17]    [,18]
 [1,] 1.529412 1.677419 2.051282 2.387755 2.302632 2.473118 2.990291 3.537736
 [2,] 1.428571 2.043478 2.057143 2.098039 2.287879 2.780822 2.824176 3.158879
 [3,] 1.764706 1.807692 1.777778 2.185185 2.289855 2.406977 2.770000 3.151786
 [4,] 2.050000 2.074074 2.052632 2.196078 2.711864 2.840000 3.112360 3.547368
 [5,] 1.437500 1.576923 1.714286 2.100000 2.277778 2.485294 2.586957 3.135417
 [6,] 1.444444 1.680000 1.707317 2.058824 2.338235 2.592593 2.923913 3.300971
 [7,] 2.000000 2.166667 2.205128 2.301887 2.710145 2.886364 3.357895 4.021277
 [8,] 1.375000 1.533333 1.843750 2.125000 2.196429 2.457143 2.670330 3.273684
 [9,] 1.588235 1.750000 1.970588 2.060000 2.311475 2.671642 2.892857 3.151515
[10,] 2.000000 1.857143 1.911765 2.019608 2.161765 2.635135 3.023256 3.692308
[11,] 1.333333 1.565217 1.729730 1.823529 1.972222 2.232558 2.758242 3.117647
[12,] 1.923077 1.947368 2.555556 2.741379 3.142857 3.575342 3.833333 4.130435
[13,] 1.615385 1.941176 1.864865 1.942308 2.274194 2.546667 2.744681 3.141509
[14,] 2.000000 2.296296 2.361111 2.312500 2.424242 2.340909 2.656566 3.157407
[15,] 2.076923 2.451613 2.742857 3.282051 2.842105 3.069444 3.255556 3.677083
[16,] 1.677419 2.272727 2.684211 2.518519 2.608696 2.602273 2.939394 3.318182
[17,] 1.625000 2.071429 2.300000 2.322581 2.239130 2.385965 2.465753 2.741573
[18,] 1.615385 2.068966 2.307692 2.260000 2.380952 2.558442 3.011765 3.544444
[19,] 1.200000 1.515152 1.837209 2.120000 2.492063 2.710843 2.939394 3.324324
[20,] 1.217391 1.400000 1.680000 1.904762 2.306667 2.792683 3.566265 3.861702
         [,19]    [,20]    [,21]    [,22]    [,23]    [,24]    [,25]     [,26]
 [1,] 3.894737 4.570175 5.472222 5.963303 6.347826 5.909722 7.808000 10.909091
 [2,] 3.845455 4.587156 5.311927 5.564103 6.465517 6.268657 7.353846  9.377193
 [3,] 3.320611 4.322314 4.785714 5.680328 6.349593 6.624060 8.846847 11.123711
 [4,] 3.849057 4.950000 5.441176 5.500000 5.733871 6.139706 7.263566  8.931624
 [5,] 3.306306 4.093458 4.619469 4.689922 5.328244 5.927536 6.685714  9.113043
 [6,] 3.586207 4.537037 5.166667 5.227642 5.562963 6.328358 7.446154  9.598214
 [7,] 4.219048 4.687500 5.342342 5.573770 6.550847 6.826772 7.793651 10.979798
 [8,] 3.387387 3.913793 4.717949 5.316239 5.609375 6.072993 6.962963  8.616667
 [9,] 3.711538 4.271028 4.598291 5.161290 5.477612 6.064748 7.480315  9.357143
[10,] 4.084211 4.804124 5.134615 5.324561 5.570312 6.036765 7.261538  9.419643
[11,] 3.692308 4.308411 4.898148 5.268908 5.492188 6.469231 7.674603 10.113208
[12,] 4.490196 5.019608 5.327273 5.508333 6.375000 7.024390 8.008197 11.294737
[13,] 3.630631 4.369369 4.743590 5.491379 5.589147 6.000000 7.208955  9.621622
[14,] 3.615385 4.146341 4.867769 5.692308 6.444444 7.151261 7.323077  9.500000
[15,] 3.814815 3.912000 4.733333 5.338710 6.729730 6.959350 8.152542 10.252427
[16,] 3.945946 4.495495 5.061947 5.244094 5.782946 6.085714 7.043796  9.398230
[17,] 2.888889 3.365217 4.114035 4.145985 4.456376 4.929936 6.291667  7.601504
[18,] 3.989474 4.480392 4.828829 5.188034 5.500000 5.617021 6.618705  8.298387
[19,] 3.815126 4.341463 4.968254 5.891667 6.346457 6.900763 9.240741 11.195876
[20,] 4.250000 4.666667 5.423423 6.089286 5.976562 7.031746 8.418803  9.990741
         [,27]    [,28]    [,29]    [,30]
 [1,] 16.55714 27.59091 53.86957 125.8000
 [2,] 16.13889 35.05714 89.57143 210.6667
 [3,] 17.05882 34.82857 73.35294 253.2000
 [4,] 14.03704 31.00000 65.63158 114.5455
 [5,] 16.06944 26.82222 54.04348 125.8000
 [6,] 16.16667 26.47826 65.73684 253.2000
 [7,] 16.58571 32.07895 69.22222 180.2857
 [8,] 12.86364 23.17308 41.20000 157.8750
 [9,] 14.30000 24.48980 51.54167 157.5000
[10,] 15.50667 33.00000 78.18750 210.6667
[11,] 14.07317 29.68293 69.55556 158.0000
[12,] 15.14474 28.13953 59.52381 422.6667
[13,] 14.41250 24.18000 49.76000 140.1111
[14,] 15.48649 27.56818 59.33333  83.8000
[15,] 15.79452 29.00000 65.89474 211.0000
[16,] 15.28000 24.57143 56.59091 140.2222
[17,] 12.12903 22.60377 47.65385 126.0000
[18,] 12.89773 26.17391 65.68421 126.1000
[19,] 16.45070 31.23077 54.08696 180.5714
[20,] 15.64865 28.25581 56.63636 157.7500

NHMSAR documentation built on Feb. 9, 2022, 9:06 a.m.

Related to MeanDurUnder in NHMSAR...