Skip to content

Commit

Permalink
Tidied up a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfTurner committed Aug 3, 2024
1 parent 637b555 commit 0831a8f
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 786 deletions.
125 changes: 0 additions & 125 deletions .Random.seed.save

This file was deleted.

20 changes: 0 additions & 20 deletions .Rhistory

This file was deleted.

95 changes: 0 additions & 95 deletions .github/workflows/rhub.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,3 @@ Further tweaks to the vignette.

Incremented the version number.
Version 0.1-6.

01/08/2024

Added a file First.R to produce a startup message.

Introduced "Gaussian sampling" as a means of generating data, under the
null hypothesis, upon which to base Monte Carlo tests.

- changed argument name "permtype" to "infertype", with possible values
"resperm", "datperm", and "gaussSample"
- replaced function permSumFns() by simSimFns()

Incremented the version number.
Version 0.1-7.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: kanova
Version: 0.1-7
Date: 2024-08-01
Version: 0.1-6
Date: 2024-07-25
Title: Pseudo Anova for K-functions
Author: Rolf Turner <rolfturner@posteo.net>
Maintainer: Rolf Turner <rolfturner@posteo.net>
Expand All @@ -13,3 +13,5 @@ VignetteBuilder: R.rsp
LazyData: true
Depends: R (>= 3.2.2)
License: GPL (>=2)
NeedsCompilation: no
Packaged: 2024-07-25 00:22:58 UTC; rolf
5 changes: 0 additions & 5 deletions R/First.R

This file was deleted.

4 changes: 3 additions & 1 deletion R/initPrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ if(is.null(B)) {
AB <- interaction(B,A)
}

# Set "splif" and check on adequacy of cell counts.
# Build Khat (the overall estimate of the unique K function, common
# to all groups under the null hypothesis of no group effects),
# and s2, the overall sample variance.
if(type %in% c("oneway","addit")) {
splif <- A
} else if(type == "interac") {
Expand Down
42 changes: 16 additions & 26 deletions R/kanova.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
kanova <- function(fmla,data,sumFnNm=c("Kest","Fest","Gest","Jest"),
test=TRUE,infertype=c("resperm","datperm","gaussSample"),
nsam=99,brief=TRUE,verb=TRUE) {
test=TRUE,permtype=c("resids","data"),nperm=99,
brief=TRUE,verb=TRUE) {
#
# Function to conduct one or two-way pseudo analysis of variance of
# Function to conduct one or two-way analysis of variance of
# summary functions (Kest, Fest, Gest, or Jest) of replicated point
# patterns classified by a grouping factor A or two grouping factors
# A and B.
#

sumFnNm <- match.arg(sumFnNm)
infertype <- match.arg(infertype)
sumFnNm <- match.arg(sumFnNm)
permtype <- match.arg(permtype)

if(length(fmla)==2) {
if(inherits(data,"hyperframe")) {
Expand Down Expand Up @@ -57,8 +57,8 @@ switch(EXPR=npreds,
if(preds[3] != paste0(Anm,":",Bnm)) {
stop("Argument \"fmla\" is of an incorrect form.\n")
}
if(infertype=="data")
stop("Cannot use infertype=\"data\" when there is interaction in the model.\n")
if(permtype=="data")
stop("Cannot use permtype=\"data\" when there is interaction in the model.\n")
type <- "interac"
effNm <- paste0("interaction of ",Anm," with ",Bnm)
}
Expand All @@ -73,46 +73,36 @@ if(!test) {
rslt <- list(stat=Tobs)
} else {
rslt <- list(fmla=fmla,data=data,sumFnNm=sumFnNm,
infertype=infertype,stat=Tobs)
permtype=permtype,stat=Tobs)
}
class(rslt) <- "kanova"
return(rslt)
}

# Testing; carry out the Monte Carlo test.
# If infertype is "resperm", create the fitted values and residuals.
if(infertype=="resperm") {
# If permtype is "resids", create the fitted values and residuals.
if(permtype=="resids") {
rAndF <- resAndFit(iDat,type) # List with components "resids" and "fitVals".
} else {
rAndF <- NULL
}
if(infertype=="gaussSample") {
splif <- switch(EXPR=type,oneway="A",addit="A",interac="AB")
xxx <- with(iDat,builds2Khat(sumFns,wts,splif,do.s2=TRUE))
s2 <- xxx$s2
Khat <- xxx$Khat
} else {
splif <- NULL
s2 <- NULL
Khat <- NULL
}

Tstar <- numeric(nsam)
for(i in 1:nsam) {
sSumFns <- simSumFns(iDat[["sumFns"]],iDat[["B"]],rAndF,splif,s2,Khat,infertype)
Tstar[i] <- with(iDat,testStat(sSumFns,A,B,AB,wts,r,type=type))
Tstar <- numeric(nperm)
for(i in 1:nperm) {
pSumFns <- permSumFns(iDat[["sumFns"]],iDat[["B"]],rAndF,permtype)
Tstar[i] <- with(iDat,testStat(pSumFns,A,B,AB,wts,r,type=type))
if(verb) cat(i,"")
if(verb & i%%10 == 0) cat("\n")
}
if(verb & i%%10 != 0) cat("\n")
m <- sum(Tstar >= Tobs)
pv <- (m+1)/(nsam+1)
pv <- (m+1)/(nperm+1)
bres <- list(EffectName=effNm,stat=Tobs,pvalue=pv)
if(brief) {
rslt <- bres
} else {
rslt <- c(bres,list(fmla=fmla,data=data,sumFnNm=sumFnNm,
infertype=infertype,Tstar=Tstar))
permtype=permtype,Tstar=Tstar))
}
class(rslt) <- "kanova"
rslt
Expand Down
Loading

0 comments on commit 0831a8f

Please sign in to comment.