c("DescTools", "robustbase")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
c(17, 30, 30, 25, 23, 21)
age <- length(age)
N <- mean(age)
M <-var(age)
[1] 26.26667
sd(age)
[1] 5.125102
cov.wt(as.matrix(age), method="ML")) (cML <-
$cov
[,1]
[1,] 21.88889
$center
[1] 24.33333
$n.obs
[1] 6
diag(cML$cov)) (vML <-
[1] 21.88889
sqrt(vML)
[1] 4.678556
library(DescTools)
Winsorize(age, probs=c(0.2, 0.8))
ageWins <-var(ageWins)
[1] 17.2
sd(ageWins)
[1] 4.147288
quantile(age)
0% 25% 50% 75% 100%
17.00 21.50 24.00 28.75 30.00
IQR(age)
[1] 7.25
library(DescTools)
MeanAD(age)
[1] 4
mad(age)
[1] 6.6717
library(robustbase)
Qn(age)
[1] 6.792788
scaleTau2(age)
[1] 4.865323
factor(c("C", "D", "A", "D", "E", "D", "C", "E", "E", "B", "E"),
fac <-levels=c(LETTERS[1:5], "Q"))
nlevels(fac)
P <- prop.table(table(fac))) (Fj <-
fac
A B C D E Q
0.09090909 0.09090909 0.18181818 0.27272727 0.36363636 0.00000000
First, calculate Shannon index, then diversity measure.
library(DescTools)
Entropy(Fj, base=exp(1))
shannonIdx <- (1/log(P)) * shannonIdx) (H <-
[1] 0.8193845
library(DescTools)
Skew(age)
[1] -0.08611387
Kurt(age)
[1] -1.772568
try(detach(package:robustbase))
try(detach(package:DescTools))
R markdown - markdown - R code - all posts