---
title: "Fitted distributions (extension method)"
output:
  html_document: default
  pdf_document: default
  word_document: default
date: "`r format(Sys.time(), '%d %B %Y, %H:%M')`"
fontsize: 11pt
params:
  fit1: NA
  fit2: NA
  cp: NA
  d: NA
  m1: NA
  m2: NA
  yLimits: NA
  link: NA
  yCP: NA
  xMed: NA
  df1: NA
  ry: NA
  
---

# Marginal distribution of $Y$

```{r global_options, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE,
                      fig.pos = 'h',
                      fig.align = 'center',
                      fig.height = 3,
                      fig.width = 4)
```


```{r, echo = FALSE}
fit <- params$fit1
bin.left <- NA
bin.right <- NA
chips <- NA
roulette <- FALSE
filename <- system.file("shinyAppFiles", "distributionsChild.Rmd", package="SHELF")
```

```{r child=filename}
```

# Conditional distribution of $X$, given $Y$ takes its median value $y_{0.5}$


```{r, echo = FALSE}
fit <- params$fit2
```

```{r child=filename}
```

# Median function

```{r, echo = FALSE, fig.align = "center"}
plotConditionalMedianFunction(yCP = params$yCP, xMed = params$xMed, 
                              yLimits = params$yLimits,
                              link = params$link)
```


# Marginal distribution of X

```{r}
d1 <- switch(params$d[1],
                       "normal" = "normal",
                       "t" = "Student-t",
             "skewnormal" = "Skew normal",
                       "gamma" = "gamma",
                       "lognormal" = "log normal",
                       "beta" = "beta",
                       "hist" = "histogram",
                       "logt" = "log Student-t",
                       "best" = as.character(params$fit1$best.fitting[1, 1]),
             "mirrorgamma" = "mirror gamma",
             "mirrorlognormal" = "mirror log normal",
             "mirrorlogt" = "mirror log Student-t")

d2 <- switch(params$d[2],
                       "normal" = "normal",
                       "t" = "Student-t",
             "skewnormal" = "Skew normal",
                       "gamma" = "gamma",
                       "lognormal" = "log normal",
                       "logt" = "log Student-t",
                       "beta" = "beta",
                       "hist" = "histogram",
                       "best" = as.character(params$fit2$best.fitting[1, 1]),
             "mirrorgamma" = "mirror gamma",
             "mirrorlognormal" = "mirror log normal",
             "mirrorlogt" = "mirror log Student-t")
```



Marginal distribution of $X$, obtained using a `r paste(d1)` distribution for $Y$ and a `r paste(d2)` distribution for $X|Y$:

```{r, echo = FALSE, fig.align = "center", message = FALSE}
library(ggplot2)
ggplot(params$df1, aes(x = X, y = ..density..))+
        geom_density(fill = "steelblue") +
  theme_grey(base_size = 12)


```

