Statistics and electronics - lecture 2

The ASTA team

Lot variation

Cap220=read.csv(url("https://asta.math.aau.dk/datasets?file=capacitor_lot_220_nF.txt"))[,1]
summary(Cap220)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   197.2   204.8   207.9   207.9   210.9   218.6

Testing for log normality

Log normality

Cap220=read.csv(url("https://asta.math.aau.dk/datasets?file=capacitor_lot_220_nF.txt"))[,1]
ln_Error=log(Cap220/220)
qqnorm(ln_Error,ylab="ln_Error")
qqline(ln_Error,lwd=2,col="red")

Testing normality

Gearys test

Gearys test

mln_E=mean(ln_Error)
s1=sqrt(mean((ln_Error-mln_E)^2))
s0=sqrt(pi/2)*mean(abs(ln_Error-mln_E))
u=s1/s0
z_obs=sqrt(length(ln_Error))*(u-1)/0.2661
z_obs
## [1] -1.383383

Goodness of fit - die example

Goodness of fit - die example

critical_value <- qdist("chisq", .95, df = 5)

critical_value
## [1] 11.0705

Goodness of fit - normal distribution

m <- mean(ln_Error)
s <- sd(ln_Error)
breaks <- qnorm((0:10)/10, m, s)

Goodness of fit - normal distribution

observed <- table(cut(ln_Error, breaks))
names(observed) <- paste("bin", 1:10, sep = "")
observed
##  bin1  bin2  bin3  bin4  bin5  bin6  bin7  bin8  bin9 bin10 
##    25    37    25    19    28    30    21    25    25    34
chisq_obs <- sum((observed-26.9)^2)/26.9
chisq_obs
## [1] 10.21933

Goodness of fit - normal distribution

chisq_obs
## [1] 10.21933
critical_value <- qdist("chisq", .95, df = 7)

critical_value
## [1] 14.06714
p_value <- 1 - pchisq(chisq_obs, 7)
p_value
## [1] 0.1764812

Other tests of normality

shapiro.test(ln_Error)
## 
##  Shapiro-Wilk normality test
## 
## data:  ln_Error
## W = 0.99255, p-value = 0.1971

Sources of variation

The general model

Model for our data

Linear calibration

load("ab.RData")
ln_Error_corrected <- (ln_Error-ab[1])/ab[2]
hist(ln_Error_corrected, breaks = "FD", col = "wheat")

Model for calibrated data

Estimate of parameters

myl <- mean(ln_Error_corrected)
myl
## [1] -0.02686793
var(ln_Error_corrected)
## [1] 0.0003892828

Mixture of lots

cap470 <- read.table(url("https://asta.math.aau.dk/datasets?file=capacitor_lot_470_nF2.txt"))[, 1]
hist(cap470, breaks = 15, col = "greenyellow")

Transforming

ln_Error <- log(cap470/470)
ln_Error_corrected <- (ln_Error-ab[1])/ab[2]
hist(ln_Error_corrected, breaks = 15, col = "gold")

range(ln_Error_corrected)
## [1] -0.08888934  0.08323081

Mixture model

Fitting a mixture

library(mclust)
fit <- Mclust(ln_Error_corrected, 2 , "E")# 2 clusters; "E"qual variances
pr <- fit$parameters$pro[1]
pr
## [1] 0.728314
means <- fit$parameters$mean
means
##           1           2 
## -0.05174452  0.05406515
sigma <- sqrt(fit$parameters$variance$sigmasq)
sigma
## [1] 0.01692654

Comparing model and data

hist(ln_Error_corrected,breaks=15,col="lightcyan",probability = TRUE,ylim=c(0,18),main="Histogram and population curve")
curve(pr*dnorm(x,means[1],sigma)+(1-pr)*dnorm(x,means[2],sigma),-.1,.1,add=TRUE,lwd=2)

Concluding remarks