### ESD-FYS  -  module 4-2  - exercises



#### Component variation: Resistor


We return to the lot(250 components) of resistors with nominal value 1 kOhm.

* Read in data:

```{r }
R1000=read.csv(url("https://asta.math.aau.dk/datasets?file=Ohm.txt"))[,2]
```
* Investigate whether it is realistic to assume normality of `ln_Error=log(R1000/1000)` via
  - qq-plot
  - Geary's test
  - goodness of fit test
  - Shapiro-Wilks test

Hint for the goodness of fit test: The code below creates $B$ bins each having probability $1/B$ in a normal distribution with mean $\bar{x}$ and standard deviation $s$. Moreover, the expected and observed number of observation


```{r eval=FALSE}
m=mean(x)
s=sd(x)
# B=
cut_values=qnorm((0:B)/B,m,s) #breakpoints for bins
expected=length(x)/B 
observed=table(cut(x,cut_values))
```

#### Wind data

We return to the wind speed measurements
from the weather station located at Sjælsmark (in Exam 1). Load the data set:

```{r}
speed<-read.delim("https://asta.math.aau.dk/datasets?file=windSpeed.txt",header=FALSE)[,1]
```

* Make a goodness of fit test to see whether the Weibull distribution fits the data.

Hint: The code below calculates cut-values and expected and observed values in `B` bins for the data vector `x`.

```{r eval=FALSE}
intercept=-2.82   
k=slope=1.78
lambda=exp(-intercept/k)
cut_values=qweibull((0:B)/B,shape=k,scale=lambda)
expected=length(x)/B
observed=table(cut(x,cut_values))
```

#### Excercise 10.79 in [WMMY]

#### Another type of measurement variation.

* Peter Koch has done 100 consecutive measurements on a capacitor with nominal value 100 nF. We make a plot of the consecutive values and load parameters for calibration.


```{r }
Cap100=read.table(url("https://asta.math.aau.dk/datasets?file=instrument_variation_100nF_1procent.txt"))[,1]
```

```{r}
ts.plot(Cap100)
```

* This looks like the meter swings between 2 levels. 

* According to Peter, it can be due to some random mechanical impact on the system.

* Calculate `ln_Error_corrected`  and do a mixture analysis determining the two different levels of the meter.





