R Under development (unstable) (2024-03-03 r86036 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(Sim.DiffProc) Package 'Sim.DiffProc', version 4.9 browseVignettes('Sim.DiffProc') for more informations. > > > ## Example 1: > > # SDE's 2d > fx <- expression(5*(-1-y)*x , 5*(-1-x)*y) > gx <- expression(0.5 , 0.5) > mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(2,-2),M=500) > > # boundary > > St <- expression(-1+5*t) > > # random fpt > > out <- fptsde2d(mod2d,boundary=St) > out Itô Sde 2D: | dX(t) = 5 * (-1 - Y(t)) * X(t) * dt + 0.5 * dW1(t) | dY(t) = 5 * (-1 - X(t)) * Y(t) * dt + 0.5 * dW2(t) | t in [0,1]. Boundary: | S(t) = -1 + 5 * t F.P.T: | T(S(t),X(t)) = inf{t >= 0 : X(t) <= -1 + 5 * t } | And | T(S(t),Y(t)) = inf{t >= 0 : Y(t) >= -1 + 5 * t } | Crossing realized 492 among 500. > summary(out) Monte-Carlo Statistics for the F.P.T of (X(t),Y(t)) | T(S(t),X(t)) = inf{t >= 0 : X(t) <= -1 + 5 * t } | And | T(S(t),Y(t)) = inf{t >= 0 : Y(t) >= -1 + 5 * t } T(S,X) T(S,Y) Mean 0.3387521 0.0727487 Variance 0.0004008 0.0002565 Median 0.3389694 0.0698733 Mode 0.3398444 0.0684433 First quartile 0.3255841 0.0619255 Third quartile 0.3512447 0.0791862 Minimum 0.2828480 0.0430992 Maximum 0.3932701 0.1522165 Skewness 0.0925895 1.3700591 Kurtosis 2.7322311 6.1671521 Coef-variation 0.0590984 0.2201691 3th-order moment 0.0000007 0.0000056 4th-order moment 0.0000004 0.0000004 5th-order moment 0.0000000 0.0000000 6th-order moment 0.0000000 0.0000000 > > # Marginal density > > denM <- dfptsde2d(out,pdf="M") > denM Marginal density for the F.P.T of X(t) | T(S,X) = inf{t >= 0 : X(t) <= -1 + 5 * t} Data: out[, "x"] (492 obs.); Bandwidth 'bw' = 0.004988977 x f(x) Min. :0.2678811 Min. : 0.001932 1st Qu.:0.3029701 1st Qu.: 0.648889 Median :0.3380591 Median : 5.645862 Mean :0.3380591 Mean : 7.110790 3rd Qu.:0.3731481 3rd Qu.:11.753469 Max. :0.4082370 Max. :21.405074 Marginal density for the F.P.T of Y(t) | T(S,Y) = inf{t >= 0 : Y(t) >= -1 + 5 * t} Data: out[, "y"] (492 obs.); Bandwidth 'bw' = 0.003355852 y f(y) Min. :0.03303167 Min. : 0.00419 1st Qu.:0.06534477 1st Qu.: 0.39119 Median :0.09765787 Median : 2.75703 Mean :0.09765787 Mean : 7.72162 3rd Qu.:0.12997096 3rd Qu.:12.24683 Max. :0.16228406 Max. :31.65309 > plot(denM) > > # Joint density > > denJ <- dfptsde2d(out,pdf="J",n=200,lims=c(0.28,0.4,0.04,0.13)) > denJ Joint density for the F.P.T of (X(t),Y(t)) | T(S,X) = inf{t >= 0 : X(t) <= -1 + 5 * t } | And | T(S,Y) = inf{t >= 0 : Y(t) >= -1 + 5 * t } Data: (x,y) (2 x 492 obs.); x y f(x,y) Min. :0.28 Min. :0.0400 Min. : 0.0000 1st Qu.:0.31 1st Qu.:0.0625 1st Qu.: 7.8959 Median :0.34 Median :0.0850 Median : 29.1431 Mean :0.34 Mean :0.0850 Mean : 90.8076 3rd Qu.:0.37 3rd Qu.:0.1075 3rd Qu.:118.7386 Max. :0.40 Max. :0.1300 Max. :609.0383 > plot(denJ) > plot(denJ,display="image") > plot(denJ,display="image",drawpoints=TRUE,cex=0.5,pch=19,col.pt='green') > plot(denJ,display="contour") > plot(denJ,display="contour",color.palette=colorRampPalette(c('white','green','blue','red'))) > > proc.time() user system elapsed 2.39 0.18 2.57