lmHyperframe: linear model of Kfunctions

Description Usage Arguments Author(s) Examples

Description

Function to take a hyperframe and fit a linear model to the data using all rows and the distance range Still very much in development so use carefully Not yet generalised to bivariate designs Not tested much yet

Usage

1
2
3
4
5
6
lmHyperframe(hyper, r, form, correction = "border", weights.type=NULL,
minsamp = NA, computeK=TRUE,  printwarnings = TRUE)
kfunclm(k, dat, form, weights)

## S3 method for class 'kfunctionlm'
print(x, ...)

Arguments

hyper

An object of class hyperframe (spatstat) containing point patterns and covariates

r

distances at which to model - must include only increasing positive numbers starting from 0

form

The names of the explanatory covariates in quotes

correction

The edge correction by name - options are those for Kest in spatstat. Defaults to 'border'

weights.type

The type of regression weights to be calculated. Options are 'nx', 'nx_A', 'nx2', 'nx2_A', 'sqrtnxny', 'nxny', 'nxny_A', 'sqrtnxny_A'

minsamp

Defines the minimum number of points that need to be in the central part of the plot (i.e. not affected by edge corrections). Defaults to NA so no cases are removed.

computeK

Controls whether hyperframe should compute K or if this is done externally.

printwarnings

Whether or not to print warnings

k

Vector of K(r) for all cases for a given distance r.

dat

Data set with covariates included in formula.

weights

Vector of weights for all cases for a given distance.

x

Object to be printed

Author(s)

Robert Bagchi Maintainer: Robert Bagchi <robert.bagchi@uconn.edu>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (hyper, r, form, correction = "border", weights.type, 
    minsamp = 1, printwarnings = TRUE) 
{
    if (min(r) > 0) 
        r <- c(0, r)
    if (!all(c("pppx") %in% names(hyper))) {
        stop("hyperframe object must include 'pppx' element")
    }
    hyper$K <- with.hyperframe(hyper, Kest(pppx, r = r, correction = correction, 
        ratio = TRUE))
    hyper$wts <- with.hyperframe(hyper, list(kfunc.weights.calc(pppx, 
        r = K$r, correction = correction, type = weights.type)))
    sp.keep <- sapply(hyper$wts, function(x) all(unlist(x[r]) >= 
        minsamp))
    removed.species <- row.names(hyper)[!sp.keep]
    warning(paste("Removed", length(removed.species), "species with insufficient numbers"))
    hyper <- hyper[sp.keep, ]
    dist.keep <- (apply(sapply(hyper$K, function(K) K[[correction]]), 
        1, function(x) var(x)) > 0)
    warning(paste("Not modelling K at distances ", paste(r[!dist.keep], 
        collapse = ", "), "due to zero variance"))
    modr <- match(r[dist.keep], r)
    kmods <- sapply(modr, function(i) {
        kfunclm(k = sapply(hyper$K, function(k) k[[correction]][i]), 
            dat = as.data.frame(hyper, warn = FALSE), form = form, 
            weights = sapply(hyper$wts, function(w) unlist(w)[i]))
    }, simplify = FALSE)
    names(kmods) <- r[dist.keep]
    class(kmods) <- "kfunctionlm"
    return(kmods)
  }

robertbagchi/ReplicatedPointPatterns documentation built on May 27, 2019, 10:32 a.m.