Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
thomvolker committed Mar 5, 2024
1 parent 0c083fd commit cb4fe0c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ follows.

``` r
summary(fit, test = TRUE)
#>
#> Call:
#> ulsif(df_numerator = numerator_data$x5, df_denominator = denominator_data$x5, nsigma = 5, nlambda = 5)
#>
#> Kernel Information:
#> Kernel type: Gaussian with L2 norm distances
#> Number of kernels: 200
#>
#> Optimal sigma: 0.8951539
#> Optimal lambda: 0.03162278
#> Optimal kernel weights (loocv): num [1:201] 0.14182 0.01957 0.00488 0.01596 0.01461 ...
#>
#> Pearson divergence between P(nu) and P(de): 0.2871
#> Pr(P(nu)=P(de)) < .001
#> Bonferroni-corrected for testing with r(x) = P(nu)/P(de) AND r*(x) = P(de)/P(nu).
```

The probability that numerator and denominator samples share a common
Expand Down Expand Up @@ -153,7 +168,8 @@ ggplot() +
text = element_text(size = 20))
```

<img src="man/figures/README-plot-univ-1.svg" data-fig-align="center" />
<img src="man/figures/README-plot-univ-1.svg" style="width:15cm"
data-fig-align="center" />

### Categorical data

Expand Down Expand Up @@ -185,9 +201,9 @@ aggregate(
FUN = unique
)
#> numerator_data$x1 predict(fit_cat)
#> 1 A 1.3731403
#> 2 B 1.3621401
#> 3 C 0.6291639
#> 1 A 1.3596470
#> 2 B 1.3687135
#> 3 C 0.6290922


table(numerator_data$x1) / table(denominator_data$x1)
Expand All @@ -209,6 +225,21 @@ fit_all <- ulsif(
)

summary(fit_all, test = TRUE, parallel = TRUE)
#>
#> Call:
#> ulsif(df_numerator = data.frame(lapply(numerator_data, as.numeric)), df_denominator = data.frame(lapply(denominator_data, as.numeric)))
#>
#> Kernel Information:
#> Kernel type: Gaussian with L2 norm distances
#> Number of kernels: 200
#>
#> Optimal sigma: 1.473857
#> Optimal lambda: 0.3359818
#> Optimal kernel weights (loocv): num [1:201] 0.1771 -0.0255 -0.0131 0.0979 0.0354 ...
#>
#> Pearson divergence between P(nu) and P(de): 0.4736
#> Pr(P(nu)=P(de)) < .001
#> Bonferroni-corrected for testing with r(x) = P(nu)/P(de) AND r*(x) = P(de)/P(nu).
```

### Other density ratio estimation functions
Expand Down Expand Up @@ -251,7 +282,7 @@ ggplot(data = NULL, aes(x = newx5)) +
text = element_text(size = 20))
```

<img src="man/figures/README-plot-methods-1.svg"
<img src="man/figures/README-plot-methods-1.svg" style="width:15cm"
data-fig-align="center" />

The figure directly shows that `ulsif()` and `kliep()` come rather close
Expand Down
14 changes: 6 additions & 8 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ without estimating the numerator and denominator density separately. Density rat
#| out-width: 15cm
#| fig-dpi: 500
#| fig-format: svg
#| fig-align: "center"
#| fig-align: center
set.seed(1)
library(ggplot2)
Expand All @@ -102,9 +102,7 @@ dratio <- function(x, p, dif, mu, sd) {
fit <- densityratio::ulsif(
df_numerator = densityratio::numerator_data$x5,
df_denominator = densityratio::denominator_data$x5,
centers = c(densityratio::numerator_data$x5, densityratio::denominator_data$x5),
nsigma = 2,
nlambda = 2
centers = c(densityratio::numerator_data$x5, densityratio::denominator_data$x5)
)
ggplot() +
Expand Down Expand Up @@ -198,7 +196,6 @@ summary(fit)
To formally evaluate whether the numerator and denominator densities differ significantly, you can perform a two-sample homogeneity test as follows.

```{r}
#| eval: false
summary(fit, test = TRUE)
```

Expand All @@ -210,8 +207,9 @@ Using these variables, we can obtain the estimated density ratio using `predict(

```{r}
#| label: plot-univ
#| fig-height: 7
#| fig-height: 6
#| fig-width: 10
#| out-width: 15cm
#| fig-dpi: 500
#| fig-format: svg
#| fig-align: "center"
Expand Down Expand Up @@ -267,7 +265,6 @@ table(numerator_data$x1) / table(denominator_data$x1)
After transforming all variables to numeric variables, it is possible to calculate the density ratio over the entire multivariate space of the data.

```{r}
#| eval: false
fit_all <- ulsif(
df_numerator = numerator_data |> lapply(as.numeric) |> data.frame(),
df_denominator = denominator_data |> lapply(as.numeric) |> data.frame()
Expand All @@ -287,8 +284,9 @@ Besides `ulsif()`, the package contains several other functions to estimate a de

```{r}
#| label: plot-methods
#| fig-height: 7
#| fig-height: 6
#| fig-width: 10
#| out-width: 15cm
#| fig-dpi: 500
#| fig-format: svg
#| fig-align: "center"
Expand Down

0 comments on commit cb4fe0c

Please sign in to comment.