aa

Time series analysis – YouTube

V14.16 – Testing Mediation in SPSS – Example 1 – YouTube

set.seed(9850)
df = data.frame(cat=rep(c(“S”,”M”,”T”),c(3000,4000,3000)),
ht=c(rnorm(3000, mean=100, sd=5),
rnorm(4000, mean=140, sd=5),
rnorm(3000, mean=170, sd=5)))
head(df)
tail(df)
mean(df$ht)
table(df$cat)
var(df$ht)
sd(df$ht)
aggregate(df$ht ~ df$cat, FUN=mean)
aggregate(ht~cat,df,function(s)
c(mean=mean(s),sd=sd(s),n=length(s)))

Generating 1000 SRS, size n=50,

set.seed(9850)
xbar = apply(replicate(1000, sample(df$ht, 50)),2, FUN=mean)
head(xbar)
mean(xbar)
var(xbar)
sd(xbar)
sigmasq_xbar = ((var(df$ht) * (length(df$ht) – 1)) / length(df$ht)) / 50
sigmasq_xbar_hat = var(xbar)

proportional stratified RS using category for strata

table(df$cat) / nrow(df) * 50
xbarStrat = NA
set.seed(9850)
for (i in 1:1000) {xbarStrat[i] = mean( c(df[sample(3000, 15), “ht”], df[sample(3001:7000, 20), “ht”], df[sample(7001:10000, 15), “ht”] )) }
head(xbarStrat)
mean(xbarStrat)
var(xbarStrat)