R code used at VAPMS Selected Applications of Mathematical Statistics, summer semester 2018/2019.

Class 2 (Feb 21 2019)

Plotting graph of a function:
x <- seq (-5,5,length=100)
plot (x, sin(x), type="l")
Normal distribution:
Norm <- function (x,sigma,m)
{
	return (1/(sigma * sqrt(2*pi)) * exp(-0.5*((x-m)/sigma)^2));
}	
Plotting 3 normal distributions together:
plot (x, Norm(x,1,0), type="l")
lines (x, Norm(x,2,0), type="l", col="green")
lines (x, Norm(x,1,4), type="l", col="blue")
Load package MASS. Plotting histogram of SP500 data from there against normal distribution:
hist (SP500, 100, freq=F)
lines (x, Norm(x, sd(SP500), mean(SP500)), type="l", col="blue")
lines (x, Norm(x, 0.8*sd(SP500), mean(SP500)), type="l", col="blue")
Laplace distribution:
Lap <- function (x,b,m)
{
	return (1/(2*b) * exp(- abs(x-m)/b));
}
lines (x, Lap(x, sd(SP500)/sqrt(2), mean(SP500)), type="l", col="green")
Logistic distribution:
Log <- function (x,s,m)
{
	f <- -(x-m)/s;
	e <- exp(f);
	return (e/(s*(1+e)^2));
}	
lines (x, L(x, sd(SP500)*sqrt(3)/pi, mean(SP500)), type="l", col="red")

Created: Wed Sep 30 2015
Last modified: Thu Feb 21 18:11:40 CET 2019