This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (na.omit) | |
x <- x[!is.na(x)] | |
n <- length(x) | |
m <- mean(x) | |
s <- sd(x) | |
t <- (m-1)/(s/n^0.5) | |
med <- median(x) | |
skew <- sum((x-m)^3/s^3)/n | |
ses <- ((6*n*(n-1))/((n-1)*(n+1)*(n+3)))^0.5 | |
kurt <- sum((x-m)^4/s^4)/n - 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create the lagged variable | |
da$GDPl <- c(rep(NA, 1), da$GDP)[1:length(da$GDP)] | |
# calculate the percentage | |
da$GDPr <- (da$GDP - da$GDPl)/da$GDPl | |
# or with data from latest to oldest | |
da$SPYl <- c(da$SPY[2:length(da$SPY)], rep(NA, 1)) | |
da$SPYr <- (da$SPY - da$SPYl)/da$SPYl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mosaicplot(x2, main = "Blue and Green Cabs correct and incorrect identification", | |
xlab = "Cab colour", ylab = "Identification", color = colours) | |
# set the text position as a percentage of the plot space for x and y. | |
text(x = 0.1, y = 0.5, label = 0.12) | |
text(x = 0.1, y = 0.9, label = 0.03) | |
text(x = 0.6, y = 0.5, label = 0.68) | |
text(x = 0.6, y = 0.9, label = 0.17) | |
text(x = 15, y = 16, labels = "12.5", pos = 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# xaxt will determine the x axis. = "n" leave clear. | |
plot(form, type='o', main="Grades Relative to Average (av=1)", xaxt = 'n') | |
axis(1,1:6,labels=c("AS", "A","B","C","D","FU")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://stackoverflow.com/questions/14614710/calculate-percentage-change-in-an-r-data-frame | |
SPY.R <- diff(da$SPY)/da$SPY[-length(da$SPY)] | |
TLT.R <- diff(da$TLT)/da$TLT[-length(da$TLT)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{tikzpicture} | |
%\draw[very thin, color = gray](0, 0) grid (12, 6); | |
\tikzstyle{block} = [draw, rectangle, text width = 5em, | |
text centered, minimum height = 6mm, node distance = 5em]; | |
\tikzstyle{line} = [draw, -stealth, thick] | |
\node [block] at (1.5, 4) (one) {\scriptsize True 'market' \\ (unobserved)}; | |
\node [block] at (5, 4) (two) {\scriptsize Passive investable \\ benchmark}; | |
\node [block] at (8.5, 4) (three) {\scriptsize Rebalanced \\ benchmark}; | |
\node [block] at (8.5, 2) (four) {\scriptsize Factor \\ tilts}; | |
\node [block] at (8.5, 0) (five) {\scriptsize Active \\ Portfolio}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage[absolute, overlay]{textpos} | |
\begin{frame}{Price comparison} | |
\begin{textblock*}{5cm}(1cm, 1.5cm) % (block width) (coords) | |
\includegraphics[width = 5cm]{./Pictures/ebaylogo} | |
\end{textblock*} | |
\begin{textblock*}{5cm}(6cm, 4cm) | |
\includegraphics[width = 5cm]{./Pictures/gocompare} | |
\end{textblock*} | |
\end{frame} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{frame}{Normal distribution} | |
<<norm, fig.height=4.6, echo=FALSE, warning=FALSE>>= | |
x <- seq(-3, 3, 0.1) | |
fs = function(x, epsilon, delta){ | |
dnorm(sinh(delta*asinh(x) - epsilon)) * delta*cosh(delta*asinh(x) - | |
epsilon)/sqrt(1 + x^2) | |
} | |
plot(x, fs(x, 0, 1), type = 'l', col = 'darkgreen', main = 'Normal Distribution', | |
xlab = 'Return', ylab = 'frequency', ylim = c(0, 0.6)) | |
# http://stats.stackexchange.com/questions/43482/transformation-to-increase-kurtosis-and-skewness-of-normal-r-v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is not mine. I forget whoes it is. Sorry. By all means let me know and I will add it | |
acf2=function(series,max.lag=NULL){ | |
num=length(series) | |
if (is.null(max.lag)) max.lag=ceiling(10+sqrt(num)) | |
if (max.lag > (num-1)) stop("Number of lags exceeds number of observations") | |
ACF=acf(series, max.lag, plot=FALSE)$acf[-1] | |
PACF=pacf(series, max.lag, plot=FALSE)$acf | |
LAG=1:max.lag/frequency(series) | |
minA=min(ACF) | |
maxA=max(ACF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
da <- read.csv("file", stringsAsFactors = FALSE) | |
# Reduce the questions to one word | |
Questions <- c("Overall", "Organised", "Informed", "Changes", "Contract", "Teaching", "Stimulated", "Assessment", | |
"Feedback-time", "Feedback-use", "Resources") | |
#Wrap two words labels to fit on chart without overlap | |
Level <- c(paste("Strongly", "Agree", sep = "\n"), "Agree", "Unsure", "Disagree", paste("Strongly", "Disagree", sep = "\n")) | |
barplot(da[1,]) | |
str(da) | |
head(da, n = 20) | |
#------------------------------------- |
NewerOlder