Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(pipeR)
- library(ggplot2)
- dens <- function(x) {
- sapply(x, function(x)(
- if (x >= 1 && x <= exp(1)) {
- 1 / x
- } else {
- 0
- }
- ))
- }
- dens2 <- function(x) {ifelse(0 <= x & x <= 1, 1, 0)}
- stepSize <- 0.00001
- domainData <- data.table(x = seq.int(from=-stepSize, to = 3, by = stepSize))
- domainData <-
- domainData[, Y := dens(x)
- ][, X := dens2(x)
- ][, Y_CDF := cumsum(Y * stepSize)
- ][, X_CDF := cumsum(X * stepSize)] %>>%
- melt.data.table(id.vars = c('x')) %>>%
- `[`(variable %in% c('Y', 'X'), type := 'density') %>>%
- `[`(variable %in% c('Y_CDF', 'X_CDF'), type := 'cdf')
- ggplot(data = domainData, aes(x=x, color=variable, y=value)) +
- geom_line() +
- facet_grid(type~.) +
- theme_bw()
- ggsave("~/loguniform.png", units = "in", width=4, height=6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement