Description Usage Arguments Author(s) Examples

View source: R/RepSppFunctions_new.R

Fits a mixed effects model to a given hyperframe object with K function (K) and weights (wts) elements.

kfunclme and refit.lmek are internally called by lmeHyperframe.

1 2 3 4 5 6 7 8 9 |

`hyper` |
Hyperframe object created with spatstat(as.hyperframe). Must K and wts elements. |

`r` |
Distances at which to model K. Should include 0 |

`fixed` |
RHS of the fixed effects formula in quotes, without a tilda (e.g. "x1 + x2") |

`random` |
RHS of the random effects formula in quotes (e.g. "1|group") |

`correlation` |
The correlation argument for models - sent to nlme::lme and must be accepted by nlme::lme. |

`correction` |
The edge correction which must correspond to an option in spatstat::Kest |

`weights.type` |
The regression weights. Must be one of "nx", "nx_A", "nx2", "nx2_A", "sqrtnxny", "nxny", "nxny_A", "sqrtnxny_A" |

`computeK` |
Should K be computed internally. Defaults to TRUE |

`minsamp` |
The minimum number of points, after edge corrections, for a case to be included. Cases with fewer points will be excluded and row names returned as an attribute. |

`printwarnings` |
Should warnings about case or distance exclusion be reported. Defaults to TRUE |

`k` |
A vector corresponding the K(r) for all cases at a given distance r |

`dat` |
Data including the covariates used in the fixed and random parts of the model. |

`weights` |
The model weights passed to lme. |

`na.action` |
How to deal with NAs in the data set. Defaults to na.omit. |

`mod` |
An lme model at each distance. Used internally by refit.lmek |

`res.r` |
Vector of residuals. Used internally by refit.lmek |

`x` |
Object to be printed. |

Robert Bagchi Maintainer: Robert Bagchi <[email protected]>

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 37 38 39 | ```
##---- 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, fixed, random, correlation = NULL, correction = "border",
weights.type, minsamp = 10, 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(with.hyperframe(hyper, list(kfunc.weights.calc(pppx,
r = K$r, correction = correction, type = "nx"))), function(x) all(unlist(x[r]) >=
minsamp))
removed.species <- row.names(hyper)[!sp.keep]
if (printwarnings)
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)
if (printwarnings)
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) {
kfuncLme(k = sapply(hyper$K, function(k) k[[correction]][i]),
dat = as.data.frame(hyper, warn = FALSE), fixed = fixed,
random = random, correlation = correlation, weights = sapply(hyper$wts,
function(w) unlist(w)[i]))
}, simplify = FALSE)
names(kmods) <- r[dist.keep]
return(kmods)
}
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.