Skip to content

Commit

Permalink
Address two minor issues in #65
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Jun 6, 2022
1 parent 28d82fc commit bfb3af3
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 22 deletions.
8 changes: 8 additions & 0 deletions _episodes/01-introduction-to-high-dimensional-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ library("minfi")
{: .language-r}
~~~
Warning: replacing previous import 'utils::download.file' by
'restfulr::download.file' when loading 'rtracklayer'
~~~
{: .warning}
~~~
browseVignettes("minfi")
~~~
Expand Down
14 changes: 14 additions & 0 deletions _episodes/02-high-dimensional-regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ Let's read in the data for this episode:
~~~
library("here")
library("minfi")
~~~
{: .language-r}



~~~
Warning: replacing previous import 'utils::download.file' by
'restfulr::download.file' when loading 'rtracklayer'
~~~
{: .warning}



~~~
methylation <- readRDS(here("data/methylation.rds"))
~~~
{: .language-r}
Expand Down
14 changes: 14 additions & 0 deletions _episodes/03-regression-regularisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ First, let's read in the data from the last lesson.
~~~
library("here")
library("minfi")
~~~
{: .language-r}



~~~
Warning: replacing previous import 'utils::download.file' by
'restfulr::download.file' when loading 'rtracklayer'
~~~
{: .warning}



~~~
methylation <- readRDS(here("data/methylation.rds"))
## here, we transpose the matrix to have features as rows and samples as columns
Expand Down
14 changes: 14 additions & 0 deletions _episodes/04-regression-feature-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ possible combination of features to find the best one.
~~~
library("here")
library("minfi")
~~~
{: .language-r}



~~~
Warning: replacing previous import 'utils::download.file' by
'restfulr::download.file' when loading 'rtracklayer'
~~~
{: .warning}



~~~
methylation <- readRDS(here("data/methylation.rds"))
## here, we transpose the matrix to have features as rows and samples as columns
Expand Down
5 changes: 3 additions & 2 deletions _episodes/08-k-means.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,13 @@ between points in the clusters.
library("cluster")
dist_mat <- dist(pcs)
sil <- silhouette(cluster$cluster, dist = dist_mat)
plot(sil)
plot(sil, border = NA)
~~~
{: .language-r}
<img src="../fig/rmd-08-silhouette-1.png" title="plot of chunk silhouette" alt="plot of chunk silhouette" width="432" style="display: block; margin: auto;" />
Let's plot the silhouette score on the original dimensions used to cluster
the data. Here, we're mapping cluster membership to point shape, and silhouette
width to colour.
Expand Down Expand Up @@ -337,7 +338,7 @@ belong to.
> >
> >
> > ~~~
> > plot(sil5)
> > plot(sil5, border = NA)
> > ~~~
> > {: .language-r}
> >
Expand Down
14 changes: 14 additions & 0 deletions _episodes/09-hierarchical.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ with in the regression lessons. Let's load the data and look at it.

~~~
library("minfi")
~~~
{: .language-r}



~~~
Warning: replacing previous import 'utils::download.file' by
'restfulr::download.file' when loading 'rtracklayer'
~~~
{: .warning}



~~~
library("here")
library("ComplexHeatmap")
Expand Down
28 changes: 13 additions & 15 deletions _episodes/10-mixture-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ deviation) that best fit the data.
set.seed(66)
univar <- rnorm(200)
library("MASS")
opt <- fitdistr(x = univar, densfun = dnorm, start = list(mean = 1, sd = 1))
opt <- fitdistr(
x = univar,
densfun = dnorm,
start = list(mean = 1, sd = 1)
)
~~~
{: .language-r}

Expand All @@ -111,6 +115,9 @@ Warning in densfun(x, parm[1], parm[2], ...): NaNs produced


~~~
## fitdistr here produces warnings because it does not constrain sd to be > 0.
## we could stop this by supplying a lower bound in the `lower` argument
## but it doesn't make any difference.
fitted_mean <- opt$estimate[["mean"]]
fitted_sd <- opt$estimate[["sd"]]
hist(univar, freq = FALSE, breaks = "FD")
Expand All @@ -137,7 +144,8 @@ curve(
> *Hint: try `dlnorm` with parameter names `meanlog` and `sdlog`.*
>
> > ## Solution
> > 1.
> > 1. The estimates are very close to the empirical mean and SD estimates, as we
> > might expect.
> >
> > ~~~
> > opt
Expand Down Expand Up @@ -184,7 +192,8 @@ curve(
> >
> > ~~~
> > univar_exp <- exp(univar)
> > opt_exp <- fitdistr(x = univar_exp, densfun = dlnorm, start = list(meanlog = 1, sdlog = 1))
> > opt_exp <- fitdistr(x = univar_exp, densfun = dlnorm,
> > start = list(meanlog = 1, sdlog = 1))
> > ~~~
> > {: .language-r}
> >
Expand All @@ -200,6 +209,7 @@ curve(
> >
> >
> > ~~~
> > ## again, fitdistr produces warnings because it does not constrain sdlog to be > 0.
> > opt_exp
> > ~~~
> > {: .language-r}
Expand Down Expand Up @@ -273,12 +283,6 @@ It's important to note that we don't necessarily have to pick good starting
values here, though it may help. You can see that below our initial starting
"guess" is really bad in this case:
~~~
Warning: Removed 4 rows containing missing values (geom_bar).
~~~
{: .warning}
<img src="../fig/rmd-10-mixture-animation-1.png" title="Alt" alt="Alt" width="432" style="display: block; margin: auto;" />
We then assign each data point to the component that fits them better (this is
Expand All @@ -289,12 +293,6 @@ until the algorithm converges -- meaning that the components don't change from
iteration to iteration. In this simple example, the algorithm converges after
one iteration, but this won't usually be the case!
~~~
Warning: Removed 4 rows containing missing values (geom_bar).
~~~
{: .warning}
<img src="../fig/rmd-10-mix-converged-1.png" title="Alt" alt="Alt" width="432" style="display: block; margin: auto;" />
The figures shown here were made manually, to be able to step through the
Expand Down
21 changes: 16 additions & 5 deletions _episodes_rmd/10-mixture-models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ deviation) that best fit the data.
set.seed(66)
univar <- rnorm(200)
library("MASS")
opt <- fitdistr(x = univar, densfun = dnorm, start = list(mean = 1, sd = 1))
opt <- fitdistr(
x = univar,
densfun = dnorm,
start = list(mean = 1, sd = 1)
)
## fitdistr here produces warnings because it does not constrain sd to be > 0.
## we could stop this by supplying a lower bound in the `lower` argument
## but it doesn't make any difference.
fitted_mean <- opt$estimate[["mean"]]
fitted_sd <- opt$estimate[["sd"]]
hist(univar, freq = FALSE, breaks = "FD")
Expand Down Expand Up @@ -123,7 +130,8 @@ ggplot(data.frame(x = univar)) +
> *Hint: try `dlnorm` with parameter names `meanlog` and `sdlog`.*
>
> > ## Solution
> > 1.
> > 1. The estimates are very close to the empirical mean and SD estimates, as we
> > might expect.
> > ```{r stats-univar}
> > opt
> > mean(univar)
Expand All @@ -132,7 +140,9 @@ ggplot(data.frame(x = univar)) +
> > 2.
> > ```{r fit-dlnorm}
> > univar_exp <- exp(univar)
> > opt_exp <- fitdistr(x = univar_exp, densfun = dlnorm, start = list(meanlog = 1, sdlog = 1))
> > opt_exp <- fitdistr(x = univar_exp, densfun = dlnorm,
> > start = list(meanlog = 1, sdlog = 1))
> > ## again, fitdistr produces warnings because it does not constrain sdlog to be > 0.
> > opt_exp
> > mean(univar_exp)
> > sd(univar_exp)
Expand Down Expand Up @@ -194,6 +204,7 @@ plot_mixture <- function(x, means, sds, components) {
aes(x) +
geom_histogram(
aes(y = ..density.., fill = factor(paste("component", components))),
na.rm = TRUE,
alpha = 0.4
) +
lims(x = range(x) * 1.5) +
Expand Down Expand Up @@ -370,14 +381,14 @@ both variables at once. In fact, in some cases it can basically be identical:

```{r mvnorm, echo=FALSE}
xy <- mvrnorm(1000, mu = c(0, 0), Sigma = diag(2))
plot(xy)
plot(xy, xlab="x", ylab="y")
```

However, it also allows us to model sets of variables that aren't *independent*:

```{r mvnormcor, echo=FALSE}
xy <- mvrnorm(1000, mu = c(0, 0), Sigma = matrix(c(1, 0.8, 10, 1), nrow = 2, ncol = 2))
plot(xy)
plot(xy, xlab="x", ylab="y")
```

This is useful in a mixture model, because there's no reason to think that
Expand Down
Binary file modified fig/rmd-02-p-fdr-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-02-p-fwer-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-02-plot-fdr-fwer-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-chooselambda-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-coef-ridge-lm-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-elastic-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-elastic-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-heatmap-lasso-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-plot-ridge-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-03-plotlas-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-05-pca-biplot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-05-pca-biplot-ex2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-05-pca-loadings-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-08-silhouette-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-10-mvnorm-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fig/rmd-10-mvnormcor-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bfb3af3

Please sign in to comment.