knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width=6, fig.height=4 ) # Legge denne i YAML på toppen for å skrive ut til tex #output: # pdf_document: # keep_tex: true # Original: # rmarkdown::html_vignette: # toc: true
library(multiblock)
The following example uses a simulated dataset for showcasing some of the possibilities of the ASCA method.
Two categorical factors and a covariate are simulated together with a standard normal set of 10 responses.
set.seed(1) dataset <- data.frame(y = I(matrix(rnorm(24*10), ncol = 10)), x = factor(c(rep(2,8), rep(1,8), rep(0,8))), z = factor(rep(c(1,0), 12)), w = rnorm(24)) colnames(dataset$y) <- paste('Var', 1:10, sep = " ") rownames(dataset) <- paste('Obj', 1:24, sep = " ") str(dataset)
This ASCA implementation uses R's formula interface for model specification. This means that the first argument is a formula with response on the left and design on the right, separated by a tilde operator, e.g. y ~ x + z or assessment ~ assessor + candy. The names in the formula refer to variables in a data.frame (or list). Separation with plus (+) adds main effects to the model, while separation by stars (*) adds main effects and interactions, e.g. y ~ x * z. Colons (:) can be used for explicit interactions, e.g. y ~ x + z + x:z. More complicated formulas exist, but only a simple subset is supported by asca.
A basic ASCA model having two factors is fitted and printed as follows.
mod <- asca(y~x+z, data = dataset) print(mod)
Scores for first factor are extracted and a scoreplot with confidence ellipsoids is produced.
sc <- scores(mod) head(sc) scoreplot(mod, legendpos = "topleft", ellipsoids = "confidence")
This is repeated for the second factor.
sc <- scores(mod, factor = "z") head(sc) scoreplot(mod, factor = "z", ellipsoids = "confidence")
A basic loadingplot for the first factor is generated using graphics from the pls package.
lo <- loadings(mod) head(lo) loadingplot(mod, scatter = TRUE, labels = 'names')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.