From 61bd94bec844e7fbef35fffc1f016cc86b3dcb1b Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 30 Dec 2023 10:06:41 +0100 Subject: [PATCH] add: eeg.R and psqt.tex --- LaTeX/plots/psqt.tex | 43 +++++++++++++++++++ dataAnalysis/eeg/eeg.R | 93 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 LaTeX/plots/psqt.tex create mode 100644 dataAnalysis/eeg/eeg.R diff --git a/LaTeX/plots/psqt.tex b/LaTeX/plots/psqt.tex new file mode 100644 index 0000000..4416594 --- /dev/null +++ b/LaTeX/plots/psqt.tex @@ -0,0 +1,43 @@ +% Authomatically generated by `dataAnalysis/chess.R` + +\documentclass{standalone} + +\usepackage[LSB, T1]{fontenc} +\usepackage{chessboard} +\usepackage{skak} +\usepackage{tikz} +\usepackage{amsmath} +\usepackage{xcolor} + +\setboardfontencoding{LSB} + +\setchessboard{linewidth = 0.1em, showmover = false, smallboard} + +\definecolor{col1}{HTML}{5F1415} \definecolor{col2}{HTML}{641818} \definecolor{col3}{HTML}{681B1C} \definecolor{col4}{HTML}{6D1F1F} \definecolor{col5}{HTML}{722222} \definecolor{col6}{HTML}{772526} \definecolor{col7}{HTML}{7C2829} \definecolor{col8}{HTML}{812B2C} \definecolor{col9}{HTML}{862F2F} \definecolor{col10}{HTML}{8B3232} \definecolor{col11}{HTML}{903535} \definecolor{col12}{HTML}{953838} \definecolor{col13}{HTML}{9A3B3B} \definecolor{col14}{HTML}{9F3E3E} \definecolor{col15}{HTML}{A44141} \definecolor{col16}{HTML}{A94444} \definecolor{col17}{HTML}{AE4747} \definecolor{col18}{HTML}{B34A4A} \definecolor{col19}{HTML}{B74E4E} \definecolor{col20}{HTML}{BA5353} \definecolor{col21}{HTML}{BD5758} \definecolor{col22}{HTML}{C05C5C} \definecolor{col23}{HTML}{C26061} \definecolor{col24}{HTML}{C56565} \definecolor{col25}{HTML}{C7696A} \definecolor{col26}{HTML}{CA6E6E} \definecolor{col27}{HTML}{CD7272} \definecolor{col28}{HTML}{CF7677} \definecolor{col29}{HTML}{D17A7B} \definecolor{col30}{HTML}{D47F7F} \definecolor{col31}{HTML}{D68383} \definecolor{col32}{HTML}{D88787} \definecolor{col33}{HTML}{DA8B8C} \definecolor{col34}{HTML}{DC8F90} \definecolor{col35}{HTML}{DE9394} \definecolor{col36}{HTML}{E09898} \definecolor{col37}{HTML}{E29C9C} \definecolor{col38}{HTML}{E4A0A0} \definecolor{col39}{HTML}{E6A4A4} \definecolor{col40}{HTML}{E8A8A8} \definecolor{col41}{HTML}{E9ABAC} \definecolor{col42}{HTML}{EBAFAF} \definecolor{col43}{HTML}{EDB3B3} \definecolor{col44}{HTML}{EEB7B7} \definecolor{col45}{HTML}{EFBBBB} \definecolor{col46}{HTML}{F1BEBF} \definecolor{col47}{HTML}{F2C2C2} \definecolor{col48}{HTML}{F3C6C6} \definecolor{col49}{HTML}{F4C9C9} \definecolor{col50}{HTML}{F5CDCD} \definecolor{col51}{HTML}{F6D0D0} \definecolor{col52}{HTML}{F7D4D4} \definecolor{col53}{HTML}{F8D7D7} \definecolor{col54}{HTML}{F8DADA} \definecolor{col55}{HTML}{F9DEDE} \definecolor{col56}{HTML}{F9E1E1} \definecolor{col57}{HTML}{FAE4E4} \definecolor{col58}{HTML}{FAE7E7} \definecolor{col59}{HTML}{FAEAEA} \definecolor{col60}{HTML}{FAECEC} \definecolor{col61}{HTML}{F9EFEF} \definecolor{col62}{HTML}{F9F1F1} \definecolor{col63}{HTML}{F8F4F4} \definecolor{col64}{HTML}{F7F6F6} \definecolor{col65}{HTML}{F6F6F7} \definecolor{col66}{HTML}{F4F5F8} \definecolor{col67}{HTML}{F1F3F8} \definecolor{col68}{HTML}{EFF1F8} \definecolor{col69}{HTML}{ECEFF8} \definecolor{col70}{HTML}{EAEDF8} \definecolor{col71}{HTML}{E7EBF8} \definecolor{col72}{HTML}{E4E8F8} \definecolor{col73}{HTML}{E1E6F7} \definecolor{col74}{HTML}{DEE3F7} \definecolor{col75}{HTML}{DAE1F6} \definecolor{col76}{HTML}{D7DEF5} \definecolor{col77}{HTML}{D4DCF4} \definecolor{col78}{HTML}{D0D9F4} \definecolor{col79}{HTML}{CDD6F3} \definecolor{col80}{HTML}{C9D3F2} \definecolor{col81}{HTML}{C5D0F1} \definecolor{col82}{HTML}{C2CDEF} \definecolor{col83}{HTML}{BECAEE} \definecolor{col84}{HTML}{BAC7ED} \definecolor{col85}{HTML}{B6C4EC} \definecolor{col86}{HTML}{B2C1EA} \definecolor{col87}{HTML}{AEBEE9} \definecolor{col88}{HTML}{AABAE8} \definecolor{col89}{HTML}{A6B7E6} \definecolor{col90}{HTML}{A2B4E5} \definecolor{col91}{HTML}{9EB1E3} \definecolor{col92}{HTML}{9AADE2} \definecolor{col93}{HTML}{95AAE0} \definecolor{col94}{HTML}{91A6DF} \definecolor{col95}{HTML}{8DA3DD} \definecolor{col96}{HTML}{88A0DB} \definecolor{col97}{HTML}{849CDA} \definecolor{col98}{HTML}{7F99D8} \definecolor{col99}{HTML}{7A95D6} \definecolor{col100}{HTML}{7592D4} \definecolor{col101}{HTML}{708ED3} \definecolor{col102}{HTML}{6B8BD1} \definecolor{col103}{HTML}{6687CF} \definecolor{col104}{HTML}{6184CD} \definecolor{col105}{HTML}{5B80CC} \definecolor{col106}{HTML}{567DCA} \definecolor{col107}{HTML}{5079C8} \definecolor{col108}{HTML}{4975C7} \definecolor{col109}{HTML}{4372C5} \definecolor{col110}{HTML}{3B6EC3} \definecolor{col111}{HTML}{356BC1} \definecolor{col112}{HTML}{3167BC} \definecolor{col113}{HTML}{2E63B6} \definecolor{col114}{HTML}{2B60B1} \definecolor{col115}{HTML}{275CAC} \definecolor{col116}{HTML}{2459A7} \definecolor{col117}{HTML}{2055A2} \definecolor{col118}{HTML}{1C529D} \definecolor{col119}{HTML}{174E98} \definecolor{col120}{HTML}{124B93} \definecolor{col121}{HTML}{0C478E} \definecolor{col122}{HTML}{05448A} \definecolor{col123}{HTML}{004085} \definecolor{col124}{HTML}{003D80} \definecolor{col125}{HTML}{00397C} \definecolor{col126}{HTML}{003678} \definecolor{col127}{HTML}{003274} \definecolor{col128}{HTML}{002F70} + +\begin{document} +\begin{tikzpicture} + +\coordinate (pawn) at (0, 0); +\coordinate (knight) at (5, 0); +\coordinate (bishop) at (10, 0); +\coordinate (rook) at (0, -5.2); +\coordinate (queen) at (5, -5.2); +\coordinate (king) at (10, -5.2); + +\node (pawn) at (pawn) {\chessboard[color=col64,colorbackfield=a8,color=col107,colorbackfield=a7,color=col76,colorbackfield=a6,color=col66,colorbackfield=a5,color=col67,colorbackfield=a4,color=col65,colorbackfield=a3,color=col66,colorbackfield=a2,color=col64,colorbackfield=a1,color=col64,colorbackfield=b8,color=col102,colorbackfield=b7,color=col75,colorbackfield=b6,color=col66,colorbackfield=b5,color=col66,colorbackfield=b4,color=col65,colorbackfield=b3,color=col66,colorbackfield=b2,color=col64,colorbackfield=b1,color=col64,colorbackfield=c8,color=col101,colorbackfield=c7,color=col75,colorbackfield=c6,color=col66,colorbackfield=c5,color=col66,colorbackfield=c4,color=col65,colorbackfield=c3,color=col66,colorbackfield=c2,color=col64,colorbackfield=c1,color=col64,colorbackfield=d8,color=col102,colorbackfield=d7,color=col74,colorbackfield=d6,color=col66,colorbackfield=d5,color=col67,colorbackfield=d4,color=col65,colorbackfield=d3,color=col66,colorbackfield=d2,color=col64,colorbackfield=d1,color=col64,colorbackfield=e8,color=col102,colorbackfield=e7,color=col74,colorbackfield=e6,color=col66,colorbackfield=e5,color=col67,colorbackfield=e4,color=col65,colorbackfield=e3,color=col66,colorbackfield=e2,color=col64,colorbackfield=e1,color=col64,colorbackfield=f8,color=col105,colorbackfield=f7,color=col76,colorbackfield=f6,color=col66,colorbackfield=f5,color=col67,colorbackfield=f4,color=col65,colorbackfield=f3,color=col66,colorbackfield=f2,color=col64,colorbackfield=f1,color=col64,colorbackfield=g8,color=col103,colorbackfield=g7,color=col74,colorbackfield=g6,color=col66,colorbackfield=g5,color=col67,colorbackfield=g4,color=col65,colorbackfield=g3,color=col66,colorbackfield=g2,color=col64,colorbackfield=g1,color=col64,colorbackfield=h8,color=col110,colorbackfield=h7,color=col76,colorbackfield=h6,color=col67,colorbackfield=h5,color=col67,colorbackfield=h4,color=col65,colorbackfield=h3,color=col67,colorbackfield=h2,color=col64,colorbackfield=h1]}; +\node (knight) at (knight) {\chessboard[color=col88,colorbackfield=a8,color=col82,colorbackfield=a7,color=col78,colorbackfield=a6,color=col69,colorbackfield=a5,color=col70,colorbackfield=a4,color=col66,colorbackfield=a3,color=col70,colorbackfield=a2,color=col68,colorbackfield=a1,color=col105,colorbackfield=b8,color=col83,colorbackfield=b7,color=col75,colorbackfield=b6,color=col67,colorbackfield=b5,color=col68,colorbackfield=b4,color=col66,colorbackfield=b3,color=col68,colorbackfield=b2,color=col66,colorbackfield=b1,color=col88,colorbackfield=c8,color=col81,colorbackfield=c7,color=col77,colorbackfield=c6,color=col68,colorbackfield=c5,color=col69,colorbackfield=c4,color=col66,colorbackfield=c3,color=col69,colorbackfield=c2,color=col67,colorbackfield=c1,color=col104,colorbackfield=d8,color=col88,colorbackfield=d7,color=col79,colorbackfield=d6,color=col69,colorbackfield=d5,color=col70,colorbackfield=d4,color=col66,colorbackfield=d3,color=col70,colorbackfield=d2,color=col68,colorbackfield=d1,color=col88,colorbackfield=e8,color=col79,colorbackfield=e7,color=col74,colorbackfield=e6,color=col67,colorbackfield=e5,color=col68,colorbackfield=e4,color=col65,colorbackfield=e3,color=col68,colorbackfield=e2,color=col66,colorbackfield=e1,color=col92,colorbackfield=f8,color=col83,colorbackfield=f7,color=col78,colorbackfield=f6,color=col68,colorbackfield=f5,color=col70,colorbackfield=f4,color=col66,colorbackfield=f3,color=col70,colorbackfield=f2,color=col68,colorbackfield=f1,color=col125,colorbackfield=g8,color=col91,colorbackfield=g7,color=col78,colorbackfield=g6,color=col69,colorbackfield=g5,color=col70,colorbackfield=g4,color=col67,colorbackfield=g3,color=col70,colorbackfield=g2,color=col68,colorbackfield=g1,color=col93,colorbackfield=h8,color=col83,colorbackfield=h7,color=col78,colorbackfield=h6,color=col69,colorbackfield=h5,color=col70,colorbackfield=h4,color=col66,colorbackfield=h3,color=col70,colorbackfield=h2,color=col68,colorbackfield=h1]}; +\node (bishop) at (bishop) {\chessboard[color=col73,colorbackfield=a8,color=col72,colorbackfield=a7,color=col71,colorbackfield=a6,color=col80,colorbackfield=a5,color=col70,colorbackfield=a4,color=col76,colorbackfield=a3,color=col67,colorbackfield=a2,color=col66,colorbackfield=a1,color=col70,colorbackfield=b8,color=col70,colorbackfield=b7,color=col69,colorbackfield=b6,color=col74,colorbackfield=b5,color=col69,colorbackfield=b4,color=col72,colorbackfield=b3,color=col66,colorbackfield=b2,color=col68,colorbackfield=b1,color=col71,colorbackfield=c8,color=col66,colorbackfield=c7,color=col66,colorbackfield=c6,color=col78,colorbackfield=c5,color=col66,colorbackfield=c4,color=col68,colorbackfield=c3,color=col66,colorbackfield=c2,color=col67,colorbackfield=c1,color=col68,colorbackfield=d8,color=col68,colorbackfield=d7,color=col67,colorbackfield=d6,color=col70,colorbackfield=d5,color=col67,colorbackfield=d4,color=col69,colorbackfield=d3,color=col66,colorbackfield=d2,color=col67,colorbackfield=d1,color=col68,colorbackfield=e8,color=col68,colorbackfield=e7,color=col67,colorbackfield=e6,color=col71,colorbackfield=e5,color=col67,colorbackfield=e4,color=col70,colorbackfield=e3,color=col66,colorbackfield=e2,color=col65,colorbackfield=e1,color=col73,colorbackfield=f8,color=col70,colorbackfield=f7,color=col68,colorbackfield=f6,color=col82,colorbackfield=f5,color=col66,colorbackfield=f4,color=col75,colorbackfield=f3,color=col67,colorbackfield=f2,color=col65,colorbackfield=f1,color=col71,colorbackfield=g8,color=col70,colorbackfield=g7,color=col69,colorbackfield=g6,color=col73,colorbackfield=g5,color=col70,colorbackfield=g4,color=col70,colorbackfield=g3,color=col66,colorbackfield=g2,color=col79,colorbackfield=g1,color=col73,colorbackfield=h8,color=col72,colorbackfield=h7,color=col70,colorbackfield=h6,color=col79,colorbackfield=h5,color=col70,colorbackfield=h4,color=col75,colorbackfield=h3,color=col67,colorbackfield=h2,color=col64,colorbackfield=h1]}; +\node (rook) at (rook) {\chessboard[color=col104,colorbackfield=a8,color=col95,colorbackfield=a7,color=col105,colorbackfield=a6,color=col103,colorbackfield=a5,color=col97,colorbackfield=a4,color=col81,colorbackfield=a3,color=col84,colorbackfield=a2,color=col89,colorbackfield=a1,color=col95,colorbackfield=b8,color=col90,colorbackfield=b7,color=col97,colorbackfield=b6,color=col97,colorbackfield=b5,color=col92,colorbackfield=b4,color=col77,colorbackfield=b3,color=col81,colorbackfield=b2,color=col84,colorbackfield=b1,color=col105,colorbackfield=c8,color=col96,colorbackfield=c7,color=col106,colorbackfield=c6,color=col104,colorbackfield=c5,color=col98,colorbackfield=c4,color=col82,colorbackfield=c3,color=col85,colorbackfield=c2,color=col90,colorbackfield=c1,color=col89,colorbackfield=d8,color=col86,colorbackfield=d7,color=col91,colorbackfield=d6,color=col91,colorbackfield=d5,color=col87,colorbackfield=d4,color=col74,colorbackfield=d3,color=col79,colorbackfield=d2,color=col80,colorbackfield=d1,color=col93,colorbackfield=e8,color=col88,colorbackfield=e7,color=col95,colorbackfield=e6,color=col94,colorbackfield=e5,color=col90,colorbackfield=e4,color=col75,colorbackfield=e3,color=col80,colorbackfield=e2,color=col83,colorbackfield=e1,color=col100,colorbackfield=f8,color=col93,colorbackfield=f7,color=col102,colorbackfield=f6,color=col100,colorbackfield=f5,color=col95,colorbackfield=f4,color=col79,colorbackfield=f3,color=col83,colorbackfield=f2,color=col88,colorbackfield=f1,color=col97,colorbackfield=g8,color=col92,colorbackfield=g7,color=col99,colorbackfield=g6,color=col98,colorbackfield=g5,color=col93,colorbackfield=g4,color=col79,colorbackfield=g3,color=col83,colorbackfield=g2,color=col84,colorbackfield=g1,color=col106,colorbackfield=h8,color=col96,colorbackfield=h7,color=col108,colorbackfield=h6,color=col105,colorbackfield=h5,color=col99,colorbackfield=h4,color=col82,colorbackfield=h3,color=col85,colorbackfield=h2,color=col91,colorbackfield=h1]}; +\node (queen) at (queen) {\chessboard[color=col126,colorbackfield=a8,color=col125,colorbackfield=a7,color=col124,colorbackfield=a6,color=col122,colorbackfield=a5,color=col117,colorbackfield=a4,color=col110,colorbackfield=a3,color=col108,colorbackfield=a2,color=col99,colorbackfield=a1,color=col125,colorbackfield=b8,color=col125,colorbackfield=b7,color=col124,colorbackfield=b6,color=col123,colorbackfield=b5,color=col118,colorbackfield=b4,color=col111,colorbackfield=b3,color=col110,colorbackfield=b2,color=col101,colorbackfield=b1,color=col124,colorbackfield=c8,color=col126,colorbackfield=c7,color=col126,colorbackfield=c6,color=col125,colorbackfield=c5,color=col122,colorbackfield=c4,color=col117,colorbackfield=c3,color=col115,colorbackfield=c2,color=col105,colorbackfield=c1,color=col109,colorbackfield=d8,color=col118,colorbackfield=d7,color=col120,colorbackfield=d6,color=col120,colorbackfield=d5,color=col122,colorbackfield=d4,color=col124,colorbackfield=d3,color=col122,colorbackfield=d2,color=col111,colorbackfield=d1,color=col124,colorbackfield=e8,color=col128,colorbackfield=e7,color=col128,colorbackfield=e6,color=col127,colorbackfield=e5,color=col126,colorbackfield=e4,color=col122,colorbackfield=e3,color=col120,colorbackfield=e2,color=col109,colorbackfield=e1,color=col125,colorbackfield=f8,color=col126,colorbackfield=f7,color=col126,colorbackfield=f6,color=col124,colorbackfield=f5,color=col120,colorbackfield=f4,color=col114,colorbackfield=f3,color=col113,colorbackfield=f2,color=col103,colorbackfield=f1,color=col127,colorbackfield=g8,color=col125,colorbackfield=g7,color=col124,colorbackfield=g6,color=col122,colorbackfield=g5,color=col115,colorbackfield=g4,color=col106,colorbackfield=g3,color=col105,colorbackfield=g2,color=col97,colorbackfield=g1,color=col127,colorbackfield=h8,color=col123,colorbackfield=h7,color=col122,colorbackfield=h6,color=col120,colorbackfield=h5,color=col112,colorbackfield=h4,color=col102,colorbackfield=h3,color=col101,colorbackfield=h2,color=col94,colorbackfield=h1]}; +\node (king) at (king) {\chessboard[color=col55,colorbackfield=a8,color=col56,colorbackfield=a7,color=col56,colorbackfield=a6,color=col56,colorbackfield=a5,color=col56,colorbackfield=a4,color=col55,colorbackfield=a3,color=col58,colorbackfield=a2,color=col65,colorbackfield=a1,color=col57,colorbackfield=b8,color=col59,colorbackfield=b7,color=col59,colorbackfield=b6,color=col58,colorbackfield=b5,color=col58,colorbackfield=b4,color=col57,colorbackfield=b3,color=col60,colorbackfield=b2,color=col69,colorbackfield=b1,color=col58,colorbackfield=c8,color=col58,colorbackfield=c7,color=col58,colorbackfield=c6,color=col58,colorbackfield=c5,color=col58,colorbackfield=c4,color=col58,colorbackfield=c3,color=col60,colorbackfield=c2,color=col65,colorbackfield=c1,color=col57,colorbackfield=d8,color=col58,colorbackfield=d7,color=col58,colorbackfield=d6,color=col57,colorbackfield=d5,color=col57,colorbackfield=d4,color=col57,colorbackfield=d3,color=col59,colorbackfield=d2,color=col64,colorbackfield=d1,color=col57,colorbackfield=e8,color=col58,colorbackfield=e7,color=col58,colorbackfield=e6,color=col58,colorbackfield=e5,color=col58,colorbackfield=e4,color=col58,colorbackfield=e3,color=col60,colorbackfield=e2,color=col64,colorbackfield=e1,color=col62,colorbackfield=f8,color=col62,colorbackfield=f7,color=col62,colorbackfield=f6,color=col61,colorbackfield=f5,color=col61,colorbackfield=f4,color=col61,colorbackfield=f3,color=col63,colorbackfield=f2,color=col67,colorbackfield=f1,color=col61,colorbackfield=g8,color=col62,colorbackfield=g7,color=col62,colorbackfield=g6,color=col62,colorbackfield=g5,color=col62,colorbackfield=g4,color=col61,colorbackfield=g3,color=col63,colorbackfield=g2,color=col70,colorbackfield=g1,color=col60,colorbackfield=h8,color=col61,colorbackfield=h7,color=col61,colorbackfield=h6,color=col60,colorbackfield=h5,color=col60,colorbackfield=h4,color=col60,colorbackfield=h3,color=col61,colorbackfield=h2,color=col64,colorbackfield=h1]}; + +\node[anchor = north, yshift = -0.4em] at (pawn.north) {Pawn}; +\node[anchor = north, yshift = -0.4em] at (knight.north) {Knight}; +\node[anchor = north, yshift = -0.4em] at (bishop.north) {Bishop}; +\node[anchor = north, yshift = -0.4em] at (rook.north) {Rook}; +\node[anchor = north, yshift = -0.4em] at (queen.north) {Queen}; +\node[anchor = north, yshift = -0.4em] at (king.north) {King}; + +\end{tikzpicture} +\end{document} diff --git a/dataAnalysis/eeg/eeg.R b/dataAnalysis/eeg/eeg.R new file mode 100644 index 0000000..336a0c8 --- /dev/null +++ b/dataAnalysis/eeg/eeg.R @@ -0,0 +1,93 @@ +options(keep.source = TRUE, keep.source.pkgs = TRUE) + +library(tensorPredictors) + +# Load as 3D predictors `X` and flat response `y` +c(X, F, y) %<-% local({ + # Load from file + ds <- readRDS("eeg_data.rds") + + # Dimension values + n <- nrow(ds) # sample size (nr. of people) + p <- 64L # nr. of predictors (count of sensorce) + t <- 256L # nr. of time points (measurements) + + # Extract dimension names + nNames <- ds$PersonID + tNames <- as.character(seq(t)) + pNames <- unlist(strsplit(colnames(ds)[2 + t * seq(p)], "_"))[c(TRUE, FALSE)] + + # Split into predictors (with proper dims and names) and response + X <- array(as.matrix(ds[, -(1:2)]), + dim = c(person = n, time = t, sensor = p), + dimnames = list(person = nNames, time = tNames, sensor = pNames) + ) + y <- ds$Case_Control + + list(X, array(y, c(n, 1L, 1L)), y) +}) + +# fit a tensor normal model to the data sample axis 1 indexes persons) +fit.gmlm <- gmlm_tensor_normal(X, F, sample.axis = 1L) + +# Performa a LOO prediction +y.hat <- sapply(seq_len(dim(X)[1L]), function(i) { + # Fit with i'th observation removes + fit <- gmlm_tensor_normal(X[-i, , ], F[-i, , , drop = FALSE], sample.axis = 1L) + + # Reduce the entire data set + r <- as.vector(mlm(X, fit$betas, modes = 2:3, transpose = TRUE)) + # Fit a logit model on reduced data with i'th observation removed + logit <- glm(y ~ r, family = binomial(link = "logit"), + data = data.frame(y = y[-i], r = r[-i]) + ) + # predict i'th response given i'th reduced observation + y.hat <- predict(logit, newdata = data.frame(r = r[i]), type = "response") + # report progress + cat(sprintf("%3d/%d\n", i, dim(X)[1L])) + + y.hat +}) + +### Classification performance measures +# acc: Accuracy. P(Yhat = Y). Estimated as: (TP+TN)/(P+N). +(acc <- mean(round(y.hat) == y)) # 0.7868852 +# err: Error rate. P(Yhat != Y). Estimated as: (FP+FN)/(P+N). +(err <- mean(round(y.hat) != y)) # 0.2131148 +# fpr: False positive rate. P(Yhat = + | Y = -). aliases: Fallout. +(fpr <- mean((round(y.hat) == 1)[y == 0])) # 0.4 +# tpr: True positive rate. P(Yhat = + | Y = +). aliases: Sensitivity, Recall. +(tpr <- mean((round(y.hat) == 1)[y == 1])) # 0.8961039 +# fnr: False negative rate. P(Yhat = - | Y = +). aliases: Miss. +(fnr <- mean((round(y.hat) == 0)[y == 1])) # 0.1038961 +# tnr: True negative rate. P(Yhat = - | Y = -). +(tnr <- mean((round(y.hat) == 0)[y == 0])) # 0.6 +# auc: Area Under the Curve +(auc <- pROC::roc(y, y.hat, quiet = TRUE)$auc) # 0.838961 + + +with(fit.gmlm, { + par.reset <- par(mfrow = c(2, 1)) + plot(seq(0, 1, len = 256), betas[[1]], main = "Time", xlab = "Time [s]", ylab = expression(beta[1])) + plot(betas[[2]], main = "Sensors", xlab = "Sensor Index", ylab = expression(beta[2])) + par(par.reset) +}) + + +# dimX <- c(4, 3, 5) +# Omegas <- Map(function(p) { +# O <- matrix(rnorm(p^2), p) +# O %*% t(O) +# }, dimX) + +# # Numerically more stable version of `sum(log(mapply(det, Omegas)) / dimX)` +# # which is itself equivalent to `log(det(Omega)) / prod(nrow(Omega))` where +# # `Omega <- Reduce(kronecker, rev(Omegas))`. + +# Omega <- Reduce(kronecker, rev(Omegas)) +# log(det(Omega)) / prod(nrow(Omega)) + +# (det.Omega <- sum(log(mapply(det, Omegas)) / dimX)) +# sum(mapply(function(Omega) { +# sum(log(eigen(Omega, TRUE, TRUE)$values)) +# }, Omegas) / dimX)