R Under development (unstable) (2025-12-12 r89163 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 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) > > > ## 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 495 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.3407838 0.0734218 Variance 0.0004332 0.0002749 Median 0.3397345 0.0703638 Mode 0.3395577 0.0659129 First quartile 0.3268930 0.0616801 Third quartile 0.3547007 0.0816789 Minimum 0.2924059 0.0432869 Maximum 0.4071547 0.1487750 Skewness 0.2109819 1.3231472 Kurtosis 2.8566997 5.8199024 Coef-variation 0.0610757 0.2258136 3th-order moment 0.0000019 0.0000060 4th-order moment 0.0000005 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"] (495 obs.); Bandwidth 'bw' = 0.005399857 x f(x) Min. :0.2762063 Min. : 0.001694035 1st Qu.:0.3129933 1st Qu.: 0.650832189 Median :0.3497803 Median : 4.265654319 Mean :0.3497803 Mean : 6.782542437 3rd Qu.:0.3865673 3rd Qu.:12.237906137 Max. :0.4233543 Max. :19.666683283 Marginal density for the F.P.T of Y(t) | T(S,Y) = inf{t >= 0 : Y(t) >= -1 + 5 * t} Data: out[, "y"] (495 obs.); Bandwidth 'bw' = 0.003883478 y f(y) Min. :0.03163643 Min. : 0.00256984 1st Qu.:0.06383367 1st Qu.: 0.57057738 Median :0.09603092 Median : 1.97939294 Mean :0.09603092 Mean : 7.74941929 3rd Qu.:0.12822817 3rd Qu.:13.34977503 Max. :0.16042542 Max. :29.13295753 > 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 495 obs.); x y f(x,y) Min. :0.28 Min. :0.0400 Min. : 0.000000 1st Qu.:0.31 1st Qu.:0.0625 1st Qu.: 7.816838 Median :0.34 Median :0.0850 Median : 33.905408 Mean :0.34 Mean :0.0850 Mean : 89.890149 3rd Qu.:0.37 3rd Qu.:0.1075 3rd Qu.:122.429334 Max. :0.40 Max. :0.1300 Max. :476.205859 > 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 3.50 0.43 3.92