Last data update: 2014.03.03

R: Computes the likelihood function on a grid of parameters
dens.gridR Documentation

Computes the likelihood function on a grid of parameters

Description

The dens.grid.* function family is used to compute the likelihood at several points on a grid. * must be one of the following: "maxstable", "excess" or "simultoccur".

Usage

dens.grid.maxstable(...)
dens.grid.excess(...)
dens.grid.simultoccur(...)

Arguments

...

see details.

Details

dens.grid specific arguments are the following:

data

a matrix representing the data.

params

a vector giving the arguments to be passed to the likelihood function; NA indicates that the coordinate has to be replaced by multiple values on a grid (there must be two NA's in the vector).

seqx,seqy

vectors giving the values to be used to compute the likelihood for the two coordinates that are set to NA in the params vector.

ln

logical. If TRUE log-density is computed.

parallel

logical. If TRUE a parallel computation of the log-likelihood function is performed, using the snowfall package (sfInit must be called before).

Other arguments are passed to the likelihood function.

Value

returns a list l including parameters used in the call (l$params, l$seqx, l$seqy), and a matrix for the computed values of the log-likelihood: l$dens.

See Also

maxstable.l.clusters, excess.l, simultoccur.l for the likelihood functions; plot3d.densgrid for a 3D visualisation of the computed values of the log-likelihood.

Examples


# Log density of the Max-stable distribution of the Schlather process
# with the Whittle Matern correlation function
# Use larger values for n.site and n.obs for better results
n.site<-3
n.obs<-2
xy<-matrix(runif(2*n.site,0,2),ncol=2)
param<-c(0.5,1.5)
library(SpatialExtremes)
data<-t(rmaxstab(n.obs, xy, "whitmat",
    nugget = 0, range = param[1], smooth = param[2]))
cl<-build.clusters.spatial(xy)
d<-dens.grid.maxstable(data,c(NA,NA),seq(0.1,1,length=5),seq(1,2,length=5),
    category="normal",
    spatial=list(sites=xy,family=spatialWhittleMatern),
    parallel=FALSE,
    clusters=cl)
plot3d.densgrid(d)

#  Log density of the Max-stable distribution of the Brown Resnick process
# Use larger values for n.site and n.obs for better results
n.site<-4
n.obs<-3
xy<-matrix(runif(2 * n.site, 0, 2), ncol = 2)
param<-c(0.5,1)
library(SpatialExtremes)
data<-t(rmaxstab(n.obs, xy, cov.mod = "brown", range = param[1], smooth = param[2]))
cl<-build.clusters.spatial(xy)
library(snowfall)
sfInit(parallel=TRUE,cpus=4)
sfLibrary(HiDimMaxStable)
d<-dens.grid.maxstable(data,c(NA,NA),seq(0.1,1,length=5),seq(0.1,1.8,length=5),
    category="lnormal",
    spatial=list(sites=xy,family=spatialPower),
    parallel=TRUE,
    clusters=cl)
sfStop()
plot3d.densgrid(d)

#   Log density of the distribution of the vector of excesses for an
# homogeneous clustered max-stable distribution
# Use larger values for n and dimensions for better results
raw.data<-rCMS(copulas=c(copClayton,copGumbel),
    margins=c(marginLnorm,marginFrechet),
    classes=c(rep(1,4),rep(2,4)),
    params=c(0.5,1,1.5,1.7),n=10)
data<-excess.censor(raw.data)
library(snowfall)
sfInit(parallel=TRUE,cpus=4)
sfLibrary(HiDimMaxStable)
sfLibrary(VGAM)
d<-dens.grid.excess(data,c(NA,1,NA,1.7),
    seq(0.1,1,length=5),seq(1,2,length=5),
    category="copula",
    copulas=c(copClayton,copGumbel),
    margins=c(marginLnorm,marginFrechet),
            parallel=TRUE,
    classes=c(rep(1,4),rep(2,4)))
sfStop()
plot3d.densgrid(d)
    
# Log density of the distribution of the componentwise maxima
# with occurences for an homogeneous clustered max-stable distribution
# Use larger values for n and dimensions for better results
raw.data<-rCMS(copulas=c(copClayton,copGumbel),
    margins=c(marginLnorm,marginFrechet),
    classes=c(rep(1,2),rep(2,2)),
    params=c(0.5,1,1.5,1.7),n=10)
data<-maxblocks(raw.data,n.blocks=2)
library(snowfall)
sfInit(parallel=TRUE,cpus=4)
sfLibrary(HiDimMaxStable)
sfLibrary(VGAM)
d<-dens.grid.simultoccur(data$normalized.max,occur=data$classes.max,
    c(NA,1,NA,1.7),
    seq(0.1,1,length=5),seq(1,2,length=5),
    category="copula",
    copulas=c(copClayton,copGumbel),
    margins=c(marginLnorm,marginFrechet),
    classes=c(rep(1,2),rep(2,2)),
    parallel=TRUE)
sfStop()
plot3d.densgrid(d)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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(HiDimMaxStable)
Loading required package: copula
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HiDimMaxStable/dens.grid.Rd_%03d_medium.png", width=480, height=480)
> ### Name: dens.grid
> ### Title: Computes the likelihood function on a grid of parameters
> ### Aliases: dens.grid.maxstable dens.grid.excess dens.grid.simultoccur
> 
> ### ** Examples
> 
> ## No test: 
> # Log density of the Max-stable distribution of the Schlather process
> # with the Whittle Matern correlation function
> # Use larger values for n.site and n.obs for better results
> n.site<-3
> n.obs<-2
> xy<-matrix(runif(2*n.site,0,2),ncol=2)
> param<-c(0.5,1.5)
> library(SpatialExtremes)

Attaching package: 'SpatialExtremes'

The following object is masked from 'package:copula':

    rcopula

> data<-t(rmaxstab(n.obs, xy, "whitmat",
+     nugget = 0, range = param[1], smooth = param[2]))
> cl<-build.clusters.spatial(xy)
> d<-dens.grid.maxstable(data,c(NA,NA),seq(0.1,1,length=5),seq(1,2,length=5),
+     category="normal",
+     spatial=list(sites=xy,family=spatialWhittleMatern),
+     parallel=FALSE,
+     clusters=cl)
> plot3d.densgrid(d)
> 
> #  Log density of the Max-stable distribution of the Brown Resnick process
> # Use larger values for n.site and n.obs for better results
> n.site<-4
> n.obs<-3
> xy<-matrix(runif(2 * n.site, 0, 2), ncol = 2)
> param<-c(0.5,1)
> library(SpatialExtremes)
> data<-t(rmaxstab(n.obs, xy, cov.mod = "brown", range = param[1], smooth = param[2]))
> cl<-build.clusters.spatial(xy)
> library(snowfall)
Loading required package: snow
> sfInit(parallel=TRUE,cpus=4)
R Version:  R version 3.3.1 (2016-06-21) 

snowfall 1.84-6.1 initialized (using snow 0.4-1): parallel execution on 4 CPUs.

> sfLibrary(HiDimMaxStable)
Library HiDimMaxStable loaded.
Library HiDimMaxStable loaded in cluster.

> d<-dens.grid.maxstable(data,c(NA,NA),seq(0.1,1,length=5),seq(0.1,1.8,length=5),
+     category="lnormal",
+     spatial=list(sites=xy,family=spatialPower),
+     parallel=TRUE,
+     clusters=cl)
> sfStop()

Stopping cluster

> plot3d.densgrid(d)
> 
> #   Log density of the distribution of the vector of excesses for an
> # homogeneous clustered max-stable distribution
> # Use larger values for n and dimensions for better results
> raw.data<-rCMS(copulas=c(copClayton,copGumbel),
+     margins=c(marginLnorm,marginFrechet),
+     classes=c(rep(1,4),rep(2,4)),
+     params=c(0.5,1,1.5,1.7),n=10)
> data<-excess.censor(raw.data)
> library(snowfall)
> sfInit(parallel=TRUE,cpus=4)
snowfall 1.84-6.1 initialized (using snow 0.4-1): parallel execution on 4 CPUs.

> sfLibrary(HiDimMaxStable)
Library HiDimMaxStable loaded.
Library HiDimMaxStable loaded in cluster.

> sfLibrary(VGAM)
Library VGAM loaded.
Library VGAM loaded in cluster.

Loading required package: stats4
Loading required package: splines

Attaching package: 'VGAM'

The following objects are masked from 'package:SpatialExtremes':

    dgev, dgpd, logit, pgev, pgpd, qgev, qgpd, rgev, rgpd

The following objects are masked from 'package:copula':

    log1mexp, log1pexp, rlog

> d<-dens.grid.excess(data,c(NA,1,NA,1.7),
+     seq(0.1,1,length=5),seq(1,2,length=5),
+     category="copula",
+     copulas=c(copClayton,copGumbel),
+     margins=c(marginLnorm,marginFrechet),
+             parallel=TRUE,
+     classes=c(rep(1,4),rep(2,4)))
> sfStop()

Stopping cluster

> plot3d.densgrid(d)
>     
> # Log density of the distribution of the componentwise maxima
> # with occurences for an homogeneous clustered max-stable distribution
> # Use larger values for n and dimensions for better results
> raw.data<-rCMS(copulas=c(copClayton,copGumbel),
+     margins=c(marginLnorm,marginFrechet),
+     classes=c(rep(1,2),rep(2,2)),
+     params=c(0.5,1,1.5,1.7),n=10)
> data<-maxblocks(raw.data,n.blocks=2)
> library(snowfall)
> sfInit(parallel=TRUE,cpus=4)
snowfall 1.84-6.1 initialized (using snow 0.4-1): parallel execution on 4 CPUs.

> sfLibrary(HiDimMaxStable)
Library HiDimMaxStable loaded.
Library HiDimMaxStable loaded in cluster.

> sfLibrary(VGAM)
Library VGAM loaded.
Library VGAM loaded in cluster.

> d<-dens.grid.simultoccur(data$normalized.max,occur=data$classes.max,
+     c(NA,1,NA,1.7),
+     seq(0.1,1,length=5),seq(1,2,length=5),
+     category="copula",
+     copulas=c(copClayton,copGumbel),
+     margins=c(marginLnorm,marginFrechet),
+     classes=c(rep(1,2),rep(2,2)),
+     parallel=TRUE)
> sfStop()

Stopping cluster

> plot3d.densgrid(d)
> ## End(No test)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>