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. > > ## 2-dim SDE > set.seed(1234) > > # SDE's 2d > fx <- expression(3*(2-y),2*x) > gx <- expression(1,y) > mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(1,2),M=1000) > > # random > r2d <- rsde2d(mod2d,at=0.5) > summary(r2d) x y Min. :-5.6639 Min. : 0.4349 1st Qu.:-0.3902 1st Qu.: 1.7160 Median : 0.5497 Median : 2.4000 Mean : 0.3265 Mean : 2.7618 3rd Qu.: 1.2958 3rd Qu.: 3.3156 Max. : 3.3886 Max. :12.1161 > > # Marginal density > > denM <- dsde2d(mod2d,pdf="M", at=0.5) > denM Marginal density of X(t-t0)|X(t0)=1 at time t = 0.5 Data: x (1000 obs.); Bandwidth 'bw' = 0.2844 x f(x) Min. :-6.517219 Min. :0.0000234 1st Qu.:-3.827439 1st Qu.:0.0086908 Median :-1.137660 Median :0.0271170 Mean :-1.137660 Mean :0.0927625 3rd Qu.: 1.552120 3rd Qu.:0.1619789 Max. : 4.241900 Max. :0.3356289 Marginal density of Y(t-t0)|Y(t0)=2 at time t = 0.5 Data: y (1000 obs.); Bandwidth 'bw' = 0.2699 y f(y) Min. :-0.374659 Min. :0.0000169 1st Qu.: 2.950429 1st Qu.:0.0028603 Median : 6.275517 Median :0.0145151 Mean : 6.275517 Mean :0.0750389 3rd Qu.: 9.600604 3rd Qu.:0.0918127 Max. :12.925692 Max. :0.3730383 > plot(denM) > > # Joint density > denJ <- dsde2d(mod2d,pdf="J", at= 0.5) > denJ Joint density of (X(t-t0),Y(t-t0)|X(t0)=1,Y(t0)=2) at time t = 0.5 Data: (x,y) (2 x 1000 obs.); x y f(x,y) Min. :-5.663883 Min. : 0.434936 Min. :0.00000000 1st Qu.:-3.400771 1st Qu.: 3.355226 1st Qu.:0.00000933 Median :-1.137660 Median : 6.275517 Median :0.00079737 Mean :-1.137660 Mean : 6.275517 Mean :0.00869027 3rd Qu.: 1.125452 3rd Qu.: 9.195807 3rd Qu.:0.00405071 Max. : 3.388564 Max. :12.116097 Max. :0.14830190 > plot(denJ) > plot(denJ,display="contour") > > proc.time() user system elapsed 0.35 0.17 0.53