Skip to content

Commit

Permalink
remove deprecated @doctype package
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimonen committed Sep 12, 2024
1 parent 4d754eb commit dbb3dfe
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 203 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LinkingTo:
StanHeaders (>= 2.26.0)
SystemRequirements: GNU make
NeedsCompilation: yes
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
knitr,
rmarkdown,
Expand Down
3 changes: 1 addition & 2 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
#' Bug reports, PRs, enhancement ideas or user experiences in general are
#' welcome and appreciated. Create an issue in Github or email the author.
#'
#' @docType package
#' @name lgpr-package
#' @aliases lgpr
#' @useDynLib lgpr, .registration = TRUE
Expand All @@ -88,7 +87,7 @@
#' Software 76(1).
#' }
#'
NULL
"_PACKAGE"


# DATASETS ----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion dev/covr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cov <- package_coverage(line_exclusions = exclusions, pre_clean = TRUE)
report(cov)

# upload to codecov.io
#codecov(coverage = cov, token = tok)
# codecov(coverage = cov, token = tok)
6 changes: 3 additions & 3 deletions dev/exports.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ funs <- NULL
# Select rows that define exports
for (i in seq_len(L)) {
line <- s[i]
a <- grepl('export(', line, fixed = TRUE)
if(a) funs <- c(funs, line)
a <- grepl("export(", line, fixed = TRUE)
if (a) funs <- c(funs, line)
}

# Print text to be pasted to _pkgdown.yml
L <- length(funs)
for (i in seq_len(L)) {
line <- funs[i]
f <- substr(line, 8, nchar(line)-1)
f <- substr(line, 8, nchar(line) - 1)
cat(" -", f, "\n")
}
2 changes: 1 addition & 1 deletion dev/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require(lintr)
linters <- lintr::with_defaults(
object_name_linter = NULL,
open_curly_linter = NULL
)
)

# Files that are not linted
exclusions <- list("R/RcppExports.R", "R/stanmodels.R")
Expand Down
2 changes: 1 addition & 1 deletion man/add_dis_age.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjusted_c_hat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/lgpr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/new_x.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/split.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions tests/suite/Rmd/01_sleepstudy.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ plot(fit)
# Compute and plot predictions at data points (reduce = NULL)
alpha <- 0.3
p1 <- pred(fit, reduce = NULL, draws = DRAW_INDS, verbose = verbose)
plot_components(fit, p1, t_name = "Days", group_by = "Subject", alpha = alpha)
plot_components(fit, p1, t_name = "Days", group_by = "Subject", alpha = alpha)
plot_pred(fit, p1, t_name = "Days", group_by = "Subject", alpha = alpha)
```

```{r plots_2}
# Compute and plot out-of-sample predictions (reduce = mean)
x_pred <- new_x(fit, x_values = seq(0, 20, by = 0.3), group_by = "Subject",
x = "Days")
x_pred <- new_x(fit,
x_values = seq(0, 20, by = 0.3), group_by = "Subject",
x = "Days"
)
p2 <- pred(fit, x_pred, reduce = mean, verbose = verbose)
plot_components(fit, p2, t_name = "Days", group_by = "Subject")
plot_pred(fit, p2, t_name = "Days", group_by = "Subject")
Expand Down
8 changes: 5 additions & 3 deletions tests/suite/Rmd/02_orthodont.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ plot(fit)
# Compute and plot predictions at data points (reduce = NULL)
alpha <- 0.3
p1 <- pred(fit, reduce = NULL, draws = DRAW_INDS, verbose = verbose)
plot_components(fit, p1, t_name = "age", group_by = "Subject", alpha = alpha)
plot_components(fit, p1, t_name = "age", group_by = "Subject", alpha = alpha)
plot_pred(fit, p1, t_name = "age", group_by = "Subject", alpha = alpha)
```

```{r plots_2}
# Compute and plot out-of-sample predictions (reduce = mean)
x_pred <- new_x(fit, x_values = seq(2, 20, by = 0.3), group_by = "Subject",
x = "age")
x_pred <- new_x(fit,
x_values = seq(2, 20, by = 0.3), group_by = "Subject",
x = "age"
)
p2 <- pred(fit, x_pred, reduce = mean, verbose = verbose)
plot_components(fit, p2, t_name = "age", group_by = "Subject", color_by = "Sex")
plot_pred(fit, p2, t_name = "age", group_by = "Subject")
Expand Down
18 changes: 12 additions & 6 deletions tests/suite/Rmd/04_protein-liu.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ plot(fit)
# Compute and plot predictions at data points (reduce = NULL)
alpha <- 0.3
p1 <- pred(fit, reduce = NULL, draws = DRAW_INDS, verbose = verbose)
plot_components(fit, p1, t_name = "age", group_by = "id", alpha = alpha,
color_by = c(NA, NA, "group", "sex", "group", NA))
plot_components(fit, p1,
t_name = "age", group_by = "id", alpha = alpha,
color_by = c(NA, NA, "group", "sex", "group", NA)
)
plot_pred(fit, p1, t_name = "age", group_by = "id", alpha = alpha)
```

```{r plots_2}
# Compute and plot out-of-sample predictions (reduce = mean)
x_pred <- new_x(fit, x_values = seq(0, 200, by = 2), group_by = "id",
x = "age", x_ns = "diseaseAge")
x_pred <- new_x(fit,
x_values = seq(0, 200, by = 2), group_by = "id",
x = "age", x_ns = "diseaseAge"
)
p2 <- pred(fit, x_pred, reduce = mean, verbose = verbose)
plot_components(fit, p2, t_name = "age", group_by = "id",
color_by = c(NA, NA, "group", "sex", "group", NA))
plot_components(fit, p2,
t_name = "age", group_by = "id",
color_by = c(NA, NA, "group", "sex", "group", NA)
)
plot_pred(fit, p2, t_name = "age", group_by = "id")
```

Expand Down
18 changes: 12 additions & 6 deletions tests/suite/Rmd/05_protein-liu-heter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ plot(fit)
# Compute and plot predictions at data points (reduce = NULL)
alpha <- 0.3
p1 <- pred(fit, reduce = NULL, draws = DRAW_INDS, verbose = verbose)
plot_components(fit, p1, t_name = "age", group_by = "id", alpha = alpha,
color_by = c(NA, NA, "group", "sex", "group", NA))
plot_components(fit, p1,
t_name = "age", group_by = "id", alpha = alpha,
color_by = c(NA, NA, "group", "sex", "group", NA)
)
plot_pred(fit, p1, t_name = "age", group_by = "id", alpha = alpha)
```

```{r plots_2}
# Compute and plot out-of-sample predictions (reduce = mean)
x_pred <- new_x(fit, x_values = seq(0, 200, by = 2), group_by = "id",
x = "age", x_ns = "diseaseAge")
x_pred <- new_x(fit,
x_values = seq(0, 200, by = 2), group_by = "id",
x = "age", x_ns = "diseaseAge"
)
p2 <- pred(fit, x_pred, reduce = mean, verbose = verbose)
plot_components(fit, p2, t_name = "age", group_by = "id",
color_by = c(NA, NA, "group", "sex", "group", NA))
plot_components(fit, p2,
t_name = "age", group_by = "id",
color_by = c(NA, NA, "group", "sex", "group", NA)
)
plot_pred(fit, p2, t_name = "age", group_by = "id")
```

Expand Down
99 changes: 55 additions & 44 deletions tutorials/basic/basic.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ require("ggplot2")

```{r simulate, include = FALSE, eval = FALSE}
set.seed(1932)
sim <- simulate_data(N = 12,
t_data = seq(12, 96, by = 12),
covariates = c( 0,2), # covariate types (2 = cat)
lengthscales = c(16,24,1,16), # true effect lengthscales
relevances = c(0,1,1,1), # true covariate relevances
names = c("diseaseAge", "sex"),
t_jitter = 0, # jitter in time points
snr = 3) # signal-to-noise ratio
sim <- simulate_data(
N = 12,
t_data = seq(12, 96, by = 12),
covariates = c(0, 2), # covariate types (2 = cat)
lengthscales = c(16, 24, 1, 16), # true effect lengthscales
relevances = c(0, 1, 1, 1), # true covariate relevances
names = c("diseaseAge", "sex"),
t_jitter = 0, # jitter in time points
snr = 3
) # signal-to-noise ratio
dat <- sim@data
dat$y <- 100*(dat$y + 5)
dat$y <- 100 * (dat$y + 5)
a <- as.numeric(dat$id)
dat$id <- as.factor(formatC(a, width = 2, flag = "0"))
dat$group <- as.factor(as.numeric(!is.nan(dat$diseaseAge)))
Expand All @@ -59,15 +61,15 @@ In this tutorial we use simulated `testdata_002`, which is included in the
`plot_data()` function can be used to visualize the data in many ways.

``````{r pd1, fig.width=7.2, fig.height=4.8}
plot_data(testdata_002, facet_by = "id", color_by = "sex") + xlab('Age (months)')
plot_data(testdata_002, facet_by = "id", color_by = "sex") + xlab("Age (months)")
```
Coloring according to the disease-related age (`diseaseAge`) shows that
individuals 01-06 are cases and 07-12 are controls. The observed disease onset
is at around 60 months for each case individual.
``````{r pd2, fig.width=7.2, fig.height=4.8}
plot_data(testdata_002, facet_by = "id", color_by = "diseaseAge") + scale_color_gradient2() + xlab('Age (months)')
plot_data(testdata_002, facet_by = "id", color_by = "diseaseAge") + scale_color_gradient2() + xlab("Age (months)")
```
Expand Down Expand Up @@ -114,7 +116,7 @@ Here we create a model with the continuous variable `age` and categorical
variables `sex` and subject `id` as predictors for `y`.
```{r data3, fig.width=6.1, fig.height=4.3}
model <- create_model(y ~ age + age|sex + age|id, testdata_002, verbose = FALSE)
model <- create_model(y ~ age + age | sex + age | id, testdata_002, verbose = FALSE)
print(model)
```
Expand Down Expand Up @@ -156,8 +158,10 @@ are automatically multiplied by a mask for the missing values.
Here we define the formula using the advanced syntax.
```{r model_advanced}
model <- create_model(y ~ gp(age) + zs(id)*gp(age) + zs(sex)*gp(age) + gp_vm(diseaseAge) + zs(group),
testdata_002)
model <- create_model(
y ~ gp(age) + zs(id) * gp(age) + zs(sex) * gp(age) + gp_vm(diseaseAge) + zs(group),
testdata_002
)
```
We received a warning because we used `gp_vm()` without specifying a prior.
Expand Down Expand Up @@ -195,9 +199,10 @@ prior <- list(
ell = igam(shape = 5, scale = 5) # inverse gamma for lengthscales <ell>
)
model <- create_model(y ~ age + age|sex + age|id,
data = testdata_002,
prior = prior)
model <- create_model(y ~ age + age | sex + age | id,
data = testdata_002,
prior = prior
)
param_summary(model)
```
Specifying the `prior` argument as a named list gave the same prior for
Expand All @@ -206,17 +211,18 @@ for each lengthscale parameter, we could specify `ell` itself as a list
with length 3.
```{r prior_sample, eval=FALSE, include=FALSE}
#To check whether a given prior makes sense, we can sample from the prior
#predictive distribution
prior_fit <- lgp(distance ~ age + age|Sex + age|Subject, dat,
sample_f = TRUE,
prior_only = TRUE,
iter = 1000,
refresh = 200,
chains = 1)
#and compare the distribution of drawn "data" to the real data
#See more about predictive checks [here](https://cran.r-project.org/web/packages/bayesplot/vignettes/graphical-ppcs.html).
# To check whether a given prior makes sense, we can sample from the prior
# predictive distribution
prior_fit <- lgp(distance ~ age + age | Sex + age | Subject, dat,
sample_f = TRUE,
prior_only = TRUE,
iter = 1000,
refresh = 200,
chains = 1
)
# and compare the distribution of drawn "data" to the real data
# See more about predictive checks [here](https://cran.r-project.org/web/packages/bayesplot/vignettes/graphical-ppcs.html).
print(prior_fit)
ppc(prior_fit, dat)
```
Expand Down Expand Up @@ -288,12 +294,13 @@ is a shared age effect, `zs(sex)*gp(age)` is a sex-specific deviation from it,
`zs(group)` is a static offset component between the two groups (Case/Control).
```{r fit, cache=TRUE}
fit <- lgp(y ~ gp(age) + zs(id)*gp(age) + zs(sex)*gp(age) + gp_vm(diseaseAge) + zs(group),
data = testdata_002,
prior = my_prior, # defined earlier
iter = 2000,
chains = 4,
refresh = 500)
fit <- lgp(y ~ gp(age) + zs(id) * gp(age) + zs(sex) * gp(age) + gp_vm(diseaseAge) + zs(group),
data = testdata_002,
prior = my_prior, # defined earlier
iter = 2000,
chains = 4,
refresh = 500
)
```
The `lgp()` function can be given any arguments that should be passed to
Expand All @@ -313,7 +320,7 @@ print(fit)
Distribution of the parameter draws can be visualized.
```{r study3, fig.width = 6, fig.height = 3.5}
plot_draws(fit, type = 'dens')
plot_draws(fit, type = "dens")
```
The slot `fit@stan_fit` is a `stanfit` object and can therefore be studied more
Expand Down Expand Up @@ -349,7 +356,9 @@ probabilistic selection. Here we define the density to be
`stats::dbeta(x, 20, 2)`, which has most mass between $0.9$ and $1.0$.
```{r study6, fig.width = 6, fig.height = 3.5}
threshold_density <- function(x) {stats::dbeta(x, 20, 2)}
threshold_density <- function(x) {
stats::dbeta(x, 20, 2)
}
s <- select.integrate(fit, p = threshold_density)
print(s$expected)
```
Expand Down Expand Up @@ -378,10 +387,11 @@ Also the posterior distribution of each component can be visualized
```{r vis4, fig.width=7, fig.height=7}
plot_components(fit,
pred = p,
color_by = c(NA, NA, "sex", "group", "group", "group"),
ylim = c(-3,2),
ncol = 2)
pred = p,
color_by = c(NA, NA, "sex", "group", "group", "group"),
ylim = c(-3, 2),
ncol = 2
)
```
# Additional notes
Expand All @@ -396,10 +406,11 @@ posteriors are then shown only at the data points.
```{r vis5, fig.width=7, fig.height=4}
plot_pred(fit)
plot_components(fit,
color_by = c(NA, NA, "sex", "group", "group", "group"),
ylim = c(-3,2),
ncol = 2)
plot_components(fit,
color_by = c(NA, NA, "sex", "group", "group", "group"),
ylim = c(-3, 2),
ncol = 2
)
```
# Computing environment
Expand Down
Loading

0 comments on commit dbb3dfe

Please sign in to comment.