-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d6ac4b
commit 8f6c2ad
Showing
6 changed files
with
172 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
## Improvements | ||
|
||
- avoided accessing ppp objects' marks directly. | ||
- cleaned up the code | ||
|
||
|
||
# dbmss 2.9-2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
DEnvelope <- | ||
function(X, r = NULL, NumberOfSimulations = 100, Alpha = 0.05, | ||
Cases, Controls, Intertype = FALSE, Global = FALSE, verbose = interactive()) { | ||
DEnvelope <- function( | ||
X, | ||
r = NULL, | ||
NumberOfSimulations = 100, | ||
Alpha = 0.05, | ||
Cases, | ||
Controls, | ||
Intertype = FALSE, | ||
Global = FALSE, | ||
verbose = interactive()) { | ||
|
||
CheckdbmssArguments() | ||
|
||
# The only null hypothesis is random labelling (equivalently, random location) | ||
SimulatedPP <- expression(rRandomLocation(X, CheckArguments = FALSE)) | ||
|
||
# local envelope, keep extreme values for lo and hi (nrank=1) | ||
Envelope <- envelope(X, fun=Dhat, nsim=NumberOfSimulations, nrank=1, | ||
r=r, Cases=Cases, Controls=Controls, Intertype=Intertype, | ||
CheckArguments = FALSE, | ||
simulate=SimulatedPP, verbose=verbose, savefuns=TRUE | ||
) | ||
Envelope <- envelope( | ||
X, | ||
fun = Dhat, | ||
nsim = NumberOfSimulations, | ||
nrank = 1, | ||
r = r, | ||
Cases = Cases, | ||
Controls = Controls, | ||
Intertype = Intertype, | ||
CheckArguments = FALSE, | ||
simulate = SimulatedPP, | ||
verbose = verbose, | ||
savefuns = TRUE | ||
) | ||
attr(Envelope, "einfo")$H0 <- "Random Location" | ||
|
||
# Calculate confidence intervals | ||
Envelope <- FillEnvelope(Envelope, Alpha, Global) | ||
# Return the envelope | ||
return (Envelope) | ||
return(Envelope) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,70 @@ | ||
Dhat <- | ||
function(X, r = NULL, Cases, Controls = NULL, Intertype = FALSE, CheckArguments = TRUE) { | ||
Dhat <- function( | ||
X, | ||
r = NULL, | ||
Cases, | ||
Controls = NULL, | ||
Intertype = FALSE, | ||
CheckArguments = TRUE) { | ||
|
||
if (CheckArguments) { | ||
CheckdbmssArguments() | ||
} | ||
# K of cases. | ||
KCases <- Khat(X, r, Cases, Cases, CheckArguments = FALSE) | ||
KCases <- Khat( | ||
X, | ||
r = r, | ||
ReferenceType = Cases, | ||
NeighborType = Cases, | ||
CheckArguments = FALSE | ||
) | ||
# Default controls are all points except cases. Reserved name is "CoNtRoLs_" | ||
Y <- X | ||
if (is.null(Controls)) { | ||
Controls <- "CoNtRoLs_" | ||
if (Controls %in% levels(marks(Y)$PointType)) stop("A point type is named 'CoNtRoLs_'. It must be changed to use the 'Controls = NULL' option of Dhat.") | ||
if (Controls %in% levels(marks(Y)$PointType)) { | ||
stop("A point type is named 'CoNtRoLs_'. It must be changed to use the 'Controls = NULL' option of Dhat.") | ||
} | ||
levels(marks(Y)$PointType) <- c(levels(marks(Y)$PointType), Controls) | ||
marks(Y)$PointType[marks(Y)$PointType != Cases] <- Controls | ||
} | ||
# K of controls. r must be those of cases. | ||
if (Intertype) { | ||
KControls <- Khat(Y, KCases$r, Cases, Controls, CheckArguments = FALSE) | ||
KControls <- Khat( | ||
Y, | ||
r = KCases$r, | ||
ReferenceType = Cases, | ||
NeighborType = Controls, | ||
CheckArguments = FALSE | ||
) | ||
} else { | ||
KControls <- Khat(Y, KCases$r, Controls, Controls, CheckArguments = FALSE) | ||
KControls <- Khat( | ||
Y, | ||
r = KCases$r, | ||
ReferenceType = Controls, | ||
NeighborType = Controls, | ||
CheckArguments = FALSE | ||
) | ||
} | ||
# Calculate the difference (a difference between fv's yields a dataframe) | ||
Dvalues <- KCases-KControls | ||
DEstimate <- cbind(as.data.frame(KCases)[1], as.data.frame(Dvalues)[2:3]) | ||
Dvalues <- KCases - KControls | ||
DEstimate <- cbind( | ||
as.data.frame(KCases)[1], | ||
as.data.frame(Dvalues)[2:3] | ||
) | ||
|
||
# Return the values of D(r) | ||
D <- fv(DEstimate, argu="r", | ||
ylab=quote(D(r)), valu=attr(KCases, "valu"), fmla=attr(KCases, "fmla"), | ||
alim=attr(KCases, "alim"), labl=c("r", "%s[theo](r)", "hat(%s)[iso](r)"), | ||
desc=attr(KCases, "desc"), unitname=attr(KCases, "unitname"), fname="D") | ||
D <- fv( | ||
DEstimate, | ||
argu="r", | ||
ylab = quote(D(r)), | ||
valu = attr(KCases, "valu"), | ||
fmla = attr(KCases, "fmla"), | ||
alim = attr(KCases, "alim"), | ||
labl = c("r", "%s[theo](r)", "hat(%s)[iso](r)"), | ||
desc = attr(KCases, "desc"), | ||
unitname = attr(KCases, "unitname"), | ||
fname = "D" | ||
) | ||
fvnames(D, ".") <- colnames(DEstimate)[-1] | ||
return (D) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters