Skip to content

Commit

Permalink
Merge pull request #92 from gmcmacran/betterPrint
Browse files Browse the repository at this point in the history
Better print
  • Loading branch information
gmcmacran committed Sep 24, 2023
2 parents 91de23f + e4a3577 commit 8eb766c
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# NOTE: This workflow is overkill for most R packages and
# check-standard.yaml is likely a better choice.
# usethis::use_github_action("check-standard") will install it.
on:
push:
branches: [main, master]
Expand All @@ -23,19 +19,10 @@ jobs:
matrix:
config:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters: linters_with_defaults(
object_length_linter = NULL,
object_name_linter = NULL,
object_usage_linter = NULL,
indentation_linter = NULL,
duplicate_argument_linter = duplicate_argument_linter(),
equals_na_linter = equals_na_linter(),
namespace_linter = namespace_linter(),
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: LRTesteR
Title: Likelihood Ratio Tests and Confidence Intervals
Version: 1.1.0
Version: 1.1.1
Author: Greg McMahan
Maintainer: Greg McMahan <gmcmacran@gmail.com>
Description: A collection of hypothesis tests and confidence intervals based on the likelihood ratio
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# LRTesteR 1.2.0
# LRTesteR 1.1.1
* Remove "[1] " from print method.
* Update github actions.

# LRTesteR 1.1.0
* Add one sample and one way empirical quantile likelihood tests.
* Added a second objective optimization function to empirical mu test.

Expand Down
26 changes: 19 additions & 7 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@
#' print(test)
#' @export
print.lrtest <- function(x, ...) {
print(paste("Log Likelihood Statistic:", round(x$statistic, 2), sep = " "))
print(paste("p value:", round(x$p.value, 3), sep = " "))
cat(paste("Log Likelihood Statistic:", round(x$statistic, 2), sep = " "))
cat("\n")

cat(paste("p value:", round(x$p.value, 3), sep = " "))
cat("\n")
if (class(x)[1] %in% c("one_sample_case_one", "one_sample_case_two", "one_sample_case_three", "one_sample_case_four")) {
print(paste("Confidence Level: ", round(x[["conf.level"]][1], 3) * 100, "%", sep = ""))
print(paste("Confidence Interval: (", round(x[["conf.int"]][1], 3), ", ", round(x[["conf.int"]][2], 3), ")", sep = ""))
cat(paste("Confidence Level: ", round(x[["conf.level"]][1], 3) * 100, "%", sep = ""))
cat("\n")

cat(paste("Confidence Interval: (", round(x[["conf.int"]][1], 3), ", ", round(x[["conf.int"]][2], 3), ")", sep = ""))
cat("\n")
} else {
CIs <- x$conf.ints
print(paste("Confidence Level Of Set: ", round(x[["overall.conf"]][1], 3) * 100, "%", sep = ""))
print(paste("Individual Confidence Level: ", round(x[["individ.conf"]][1], 3) * 100, "%", sep = ""))
cat(paste("Confidence Level Of Set: ", round(x[["overall.conf"]][1], 3) * 100, "%", sep = ""))
cat("\n")

cat(paste("Individual Confidence Level: ", round(x[["individ.conf"]][1], 3) * 100, "%", sep = ""))
cat("\n")
for (i in seq(1, length(CIs), 1)) {
print(paste("Confidence Interval For Group ", names(CIs)[i], ": (", round(CIs[[i]][1], 3), ", ", round(CIs[[i]][2], 3), ")", sep = ""))
cat(paste("Confidence Interval For Group ", names(CIs)[i], ": (", round(CIs[[i]][1], 3), ", ", round(CIs[[i]][2], 3), ")", sep = ""))
cat("\n")
}
}

invisible(x)
}
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ knitr::opts_chunk$set(
```
# LRTesteR Overview
<!-- badges: start -->
[![R build status](https://github.com/gmcmacran/LRTesteR/workflows/R-CMD-check/badge.svg)](https://github.com/gmcmacran/LRTesteR/actions)
[![R-CMD-check](https://github.com/gmcmacran/LRTesteR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gmcmacran/LRTesteR/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/LRTesteR)](https://cran.r-project.org/package=LRTesteR)
<!-- badges: end -->

Expand All @@ -26,7 +26,7 @@ Estimated asymptotic type I and type II error rates can be found [here](https://

* Empirical Likelihood
+ mean
+ quantile
+ quantile

# Parametric Tests and Confidence Intervals
Parametric tests require a sample size of at least 50.
Expand Down
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

<!-- badges: start -->

[![R build
status](https://github.com/gmcmacran/LRTesteR/workflows/R-CMD-check/badge.svg)](https://github.com/gmcmacran/LRTesteR/actions)
[![R-CMD-check](https://github.com/gmcmacran/LRTesteR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gmcmacran/LRTesteR/actions/workflows/R-CMD-check.yaml)
[![CRAN
status](https://www.r-pkg.org/badges/version/LRTesteR)](https://cran.r-project.org/package=LRTesteR)
<!-- badges: end -->
Expand Down Expand Up @@ -67,10 +66,10 @@ library(LRTesteR)
set.seed(1)
x <- rpois(n = 100, lambda = 1)
poisson_lambda_one_sample(x = x, lambda = 1, alternative = "two.sided")
#> [1] "Log Likelihood Statistic: 0.01"
#> [1] "p value: 0.92"
#> [1] "Confidence Level: 95%"
#> [1] "Confidence Interval: (0.826, 1.22)"
#> Log Likelihood Statistic: 0.01
#> p value: 0.92
#> Confidence Level: 95%
#> Confidence Interval: (0.826, 1.22)
```

# Example 2: Confidence Interval
Expand All @@ -83,30 +82,30 @@ from a Cauchy random variable.
set.seed(1)
x <- rcauchy(n = 100, location = 3, scale = 5)
cauchy_scale_one_sample(x = x, scale = 5, alternative = "two.sided", conf.level = .90)
#> [1] "Log Likelihood Statistic: 1.21"
#> [1] "p value: 0.271"
#> [1] "Confidence Level: 90%"
#> [1] "Confidence Interval: (4.64, 7.284)"
#> Log Likelihood Statistic: 1.21
#> p value: 0.271
#> Confidence Level: 90%
#> Confidence Interval: (4.64, 7.284)
```

Setting alternative to “less” gets a lower one sided interval.

``` r
cauchy_scale_one_sample(x = x, scale = 5, alternative = "less", conf.level = .90)
#> [1] "Log Likelihood Statistic: 1.1"
#> [1] "p value: 0.865"
#> [1] "Confidence Level: 90%"
#> [1] "Confidence Interval: (0, 6.93)"
#> Log Likelihood Statistic: 1.1
#> p value: 0.865
#> Confidence Level: 90%
#> Confidence Interval: (0, 6.93)
```

Setting it to “greater” gets an upper one sided interval.

``` r
cauchy_scale_one_sample(x = x, scale = 5, alternative = "greater", conf.level = .90)
#> [1] "Log Likelihood Statistic: 1.1"
#> [1] "p value: 0.135"
#> [1] "Confidence Level: 90%"
#> [1] "Confidence Interval: (4.878, Inf)"
#> Log Likelihood Statistic: 1.1
#> p value: 0.135
#> Confidence Level: 90%
#> Confidence Interval: (4.878, Inf)
```

# Example 3: One-way Analysis
Expand All @@ -122,13 +121,13 @@ x <- c(rgamma(n = 50, shape = 1, rate = 2), rgamma(n = 50, shape = 2, rate = 2),
fctr <- c(rep(1, 50), rep(2, 50), rep(3, 50))
fctr <- factor(fctr, levels = c("1", "2", "3"))
gamma_shape_one_way(x = x, fctr = fctr, conf.level = .95)
#> [1] "Log Likelihood Statistic: 68.59"
#> [1] "p value: 0"
#> [1] "Confidence Level Of Set: 95%"
#> [1] "Individual Confidence Level: 98.3%"
#> [1] "Confidence Interval For Group 1: (0.65, 1.515)"
#> [1] "Confidence Interval For Group 2: (1.376, 3.376)"
#> [1] "Confidence Interval For Group 3: (1.691, 4.192)"
#> Log Likelihood Statistic: 68.59
#> p value: 0
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 98.3%
#> Confidence Interval For Group 1: (0.65, 1.515)
#> Confidence Interval For Group 2: (1.376, 3.376)
#> Confidence Interval For Group 3: (1.691, 4.192)
```

# Example 4: Empirical Likelihood
Expand All @@ -140,10 +139,10 @@ assumptions and work with less data.
set.seed(1)
x <- rnorm(n = 25, mean = 1, sd = 1)
empirical_mu_one_sample(x = x, mu = 1, alternative = "two.sided")
#> [1] "Log Likelihood Statistic: 0.73"
#> [1] "p value: 0.392"
#> [1] "Confidence Level: 95%"
#> [1] "Confidence Interval: (0.752, 1.501)"
#> Log Likelihood Statistic: 0.73
#> p value: 0.392
#> Confidence Level: 95%
#> Confidence Interval: (0.752, 1.501)
```

# The $\chi^2$ approximation
Expand Down
2 changes: 1 addition & 1 deletion vignettes/Analysis_of_Deviance.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ knitr::opts_chunk$set(

# Classic One-Way ANOVA

As an introduction, lets start with one way ANOVA. Here three random variables following a normal distribution with a common standard deviation are created. For this test, the null hypothesis is
As an introduction, lets start with one way ANOVA. Here three random variables following a normal distribution with a common standard deviation are created. For this test, the null hypothesis is

$$ H_{0}: \mu_0 = \mu_1 = \mu_2 $$

Expand Down
2 changes: 1 addition & 1 deletion vignettes/Nonparametric_Tests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Empirical likelihood is a nonparametric method of inference based on a data driv

## Tests For Mu

One sample and one-way tests are implemented. Note the distribution does not need to be symmetrical and less data is needed.
One sample and one-way tests are implemented. Note the distribution does not need to be symmetrical and less data is needed.

```{r part1}
library(LRTesteR)
Expand Down

0 comments on commit 8eb766c

Please sign in to comment.