-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from florianhartig/182-outlier
182 outlier
- Loading branch information
Showing
6 changed files
with
203 additions
and
137 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: "Calibration of p-values" | ||
author: "Florian Hartig" | ||
date: "6/3/2020" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
|
||
```{r} | ||
reps = 200 | ||
pVals = matrix(ncol = 6, nrow = reps) | ||
for(i in 1:reps){ | ||
testData = createData(sampleSize = 10000, overdispersion = 0, pZeroInflation = 0, randomEffectVariance = 0, family = gaussian()) | ||
fittedModel <- lm(observedResponse ~ Environment1 , data = testData) | ||
simulationOutput <- simulateResiduals(fittedModel = fittedModel, n = 100) | ||
pVals[i,1] = testOutliers(simulationOutput, plot = F, alternative = "two.sided")$p.value | ||
pVals[i,2] = testOutliers(simulationOutput, plot = F, alternative = "greater")$p.value | ||
pVals[i,3] = testOutliers(simulationOutput, plot = F, alternative = "less")$p.value | ||
pVals[i,4] = testOutliers(simulationOutput, plot = F, alternative = "two.sided", margin = "upper")$p.value | ||
pVals[i,5] = testOutliers(simulationOutput, plot = F, alternative = "greater", margin = "upper")$p.value | ||
pVals[i,6] = testOutliers(simulationOutput, plot = F, alternative = "less", margin = "upper")$p.value | ||
} | ||
``` | ||
|
||
|
||
|
||
```{r} | ||
par(mfrow = c(2,3)) | ||
for(i in 1:6) hist(pVals[,i], breaks = 50) | ||
``` | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set.seed(123) | ||
|
||
testData = createData(sampleSize = 200, overdispersion = 1, randomEffectVariance = 0) | ||
fittedModel <- glm(observedResponse ~ Environment1 , family = "poisson", data = testData) | ||
simulationOutput <- simulateResiduals(fittedModel = fittedModel) | ||
|
||
# default outlier test (with plot) | ||
testOutliers(simulationOutput) | ||
|
||
# note that default is to test outliers at both margins for both an excess and a lack | ||
# of outliers. Here we see that we mostly have an excess of outliers at the upper | ||
# margin. You see that it is an exces because the frequency of outliers is 0.055, | ||
# while expected is 0.008 | ||
|
||
# Let's see what would have happened if we would just have checked the lower margin | ||
testOutliers(simulationOutput, margin = "lower", plot = FALSE) | ||
|
||
# OK, now the frequency of outliers is 0, so we have too few, but this is n.s. against | ||
# the expectation | ||
|
||
# just for completeness, what would have happened if we would have checked both | ||
# margins, but just for a lack of outliers (i.e. underdispersion) | ||
|
||
testOutliers(simulationOutput, alternative = "less", plot = FALSE) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.