knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

All of Statistics

$$Outcome_i = (Model) + error_i$$

Measuring Fit

Utilizing the Power of the 'apply()' Functions

options(scipen = 20)
#dataset, rows/columns, function 
round(apply(quakes, 2, mean), 2)

Utilizing the Power of the 'lapply' Functions

lapply(quakes, mean)

Utilizing the Power of the 'sapply' Functions

round(sapply(quakes, mean),2)

Utilizing the Power of the 'tapply' Functions

tapply(quakes$mag, #dependent variable
       list(quakes$stations), #independent variable(s)
       mean) #function

Measuring Fit

Sum of Squared Errors

$$SD^2 = \frac {\sum_{i=1}^{n}(x_{i} - \bar{x})^2} {n}$$

Mean Squared Error

$$ MSE = \frac {SS} {df} = \frac {\sum_{i=1}^{n}(outcome_i-model_i)^2} {N-1} $$

Calculating Degrees of Freedom

Calculating Errors - Summary

The Standard Error

knitr::include_graphics("pictures/introDA3/standard_error.png")

Standard Error Applied

Standard Error Applied

psych::describe(quakes$mag)

Confidence Intervals

knitr::include_graphics("pictures/introDA3/confidence_intervals.png")

Confidence Intervals for Z-scores

Calculating Confidence Intervals

M <- apply(quakes, 2, mean)
SE <- apply(quakes, 2, function(x){ sd(x)/sqrt(length(x)) })
M + 1.96*SE # 95% confidence interval
M
M - 1.96*SE

Testing Hypotheses - (NHST)

Interpreting NHST

Test Statistics

$$Test Stat = \frac {signal}{noise} = \frac {model variance}{model error} = \frac {effect} {error}$$

Types of Tests

knitr::include_graphics("pictures/introDA3/one-tailed-vs-two-tailed-test.jpg")

The Potential Errors

knitr::include_graphics("pictures/introDA3/hypo_error_chart.png")

Type I Errors

Type II Errors

Power

How do we control for these errors?

Power of the Test

Effect Sizes

Effect Size Measures

Effect Size Measures

Example of an Effect Size

library(MOTE)
M <- tapply(quakes$mag, quakes$stations, mean)
STDEV <- tapply(quakes$mag, quakes$stations, sd)
N <- tapply(quakes$mag, quakes$stations, length)

head(M)

#compare station 10 to 11
effect <- d.ind.t(M[1], M[2],
        STDEV[1], STDEV[2],
        N[1], N[2], a = .05)
effect$d

Summary

In this section, you've learned about:



doomlab/learnSTATS documentation built on June 9, 2022, 12:54 a.m.