---
title: "NPRG audio analysis"
author: "st."
date: "`r Sys.time()`"
output:
  #bookdown::pdf_document2:
   # extra_dependencies: ["float"]
  bookdown::html_document2:
    global_numbering: TRUE
    number_sections: TRUE
   # code_download: yes
    toc: no
    toc_depth: 4
    toc_float:
       collapsed: no
       smooth_scroll: no
    self_contained: FALSE #TRUE for standalone html page knit
    css: https://ada-sub.dh-index.org/school/papers/011/style_HA.css
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
#library(rlang)
#library(xml2)
#library(stringi)
#library(lme4)
#library(R.utils)
library(knitr)
```

```{r echo=T,warning=FALSE}
#print(head)
# utest<-"[ani lo sonderzeichentest אני לאaäoöuüÄÖÜß]"
# utest<-chr_unserialise_unicode(utest)
# print(utest)
```

# HEAD
NEUROPRAGMATIK audioanalysis

```{r,echo=F,warning=F,eval=TRUE}
#source("survey_src.R")
# scred<-read.csv("../../../local/R/cred_gener.csv")
# src<-scred$api[scred$url=="nprg-pure"]
# cred<-read.csv("../../../../testeee/soscisrc.csv",sep=",")
# src<-cred$link[1]
#eval(parse(src, encoding="UTF-8"))
#src<-"nprg004.csv"
#source("import_nprg.r")
#d<-read.csv(src)
#d<-ds

```

```{r echo=F, warning=F}
#13062.NPRG_003 audio analysis, praat
#20230205(10.35)
d<-read.csv("nprg004.csv",colClasses = c("character","character","character","numeric","numeric","numeric"))
d1<-subset(d,d$tn=="f")
d2<-subset(d,d$tn=="m")
ds<-d

#output<-"pitch"
#d<-d1
boxout<-function(set,sub,output){
  d<-subset(set,set$tn==sub)
df3<-data.frame(critic=d[,output][d$condition=="critic"],doubt=d[,output][d$condition=="doubt"],
  name=d[,output][d$condition=="name"],request=d[,output][d$condition=="request"],offer=d[,output][d$condition=="offer"])
}
b1<-boxout(d,"m","pitch")
b2<-boxout(d,"f","pitch")
b3<-boxout(d,"m","intensity")
b4<-boxout(d,"f","intensity")

# boxplot(b1,col=2)
# #par(new=T)
# boxplot(b2,col=2)
# boxplot(b3,col=3)
# boxplot(b4,col=3)

laudio<-round(mean(d$duration,na.rm=T),3)
ld<-length(d$tn)
```
# the test
## abstract
wir haben 2x5x6 audioaufnahmen von jeweils 6 items (wörtern) in 5 conditionen (aussprachevarianten) von zwei sprechern aufgenommen (m,f). in praat wurden pitch und intensity analysiert, die durchschnittliche länge der aufnahmen betrug `r laudio` sec.

![praat analysis screenshot](nprg004_praat.jpeg)

## methode:
6 wörter: `r unique(d$word)`   
5 conditions: `r unique(d$condition)`   

die wörter sollten von den participants unter vorstellung der jeweiligen situation (condition) ausgesprochen werden.

# evaluation
## raw data presentation 
dataset: `r ld` observations.

```{r kablemean,echo=F,warning=F}
d1<-subset(d,d$tn=="m")
s1<-mean(d1$pitch[d1$condition=="critic"],na.rm=T)
s2<-mean(d1$pitch[d1$condition=="doubt"],na.rm=T)
s3<-mean(d1$pitch[d1$condition=="name"],na.rm=T)
s4<-mean(d1$pitch[d1$condition=="request"],na.rm=T)
s5<-mean(d1$pitch[d1$condition=="offer"],na.rm=T)
s6<-mean(d1$intensity[d1$condition=="critic"],na.rm=T)
s7<-mean(d1$intensity[d1$condition=="doubt"],na.rm=T)
s8<-mean(d1$intensity[d1$condition=="name"],na.rm=T)
s9<-mean(d1$intensity[d1$condition=="request"],na.rm=T)
s10<-mean(d1$intensity[d1$condition=="offer"],na.rm=T)

# df1<-data.frame(critic_pitch=s1,intensity_pitch=s6,doubt_pitch=s2,doubt_intensity=s7,name_pitch=s3,name_intensity=s8,request_pitch=s4,request_intensity=s9,offer_pitch=s5,offer_intensity=s10)
pitch_m<-c(s1,s2,s3,s4,s5)
int_m<-c(s6,s7,s8,s9,s10)
pitch_m<-round(pitch_m,2)
int_m<-round(int_m,2)

d1<-subset(d,d$tn=="f")
s1<-mean(d1$pitch[d1$condition=="critic"],na.rm=T)
s2<-mean(d1$pitch[d1$condition=="doubt"],na.rm=T)
s3<-mean(d1$pitch[d1$condition=="name"],na.rm=T)
s4<-mean(d1$pitch[d1$condition=="request"],na.rm=T)
s5<-mean(d1$pitch[d1$condition=="offer"],na.rm=T)
s6<-mean(d1$intensity[d1$condition=="critic"],na.rm=T)
s7<-mean(d1$intensity[d1$condition=="doubt"],na.rm=T)
s8<-mean(d1$intensity[d1$condition=="name"],na.rm=T)
s9<-mean(d1$intensity[d1$condition=="request"],na.rm=T)
s10<-mean(d1$intensity[d1$condition=="offer"],na.rm=T)

df1<-data.frame(critic_pitch=s1,intensity_pitch=s6,doubt_pitch=s2,doubt_intensity=s7,name_pitch=s3,name_intensity=s8,request_pitch=s4,request_intensity=s9,offer_pitch=s5,offer_intensity=s10)
pitch_f<-c(s1,s2,s3,s4,s5)
pitch_f<-round(pitch_f,2)
int_f<-c(s6,s7,s8,s9,s10)
int_f<-round(int_f,2)

pitchdf<-data.frame(pitch_m,pitch_f,int_m,int_f)
dfns<-c("critic","doubt","name","request","offer")
rownames(pitchdf)<-dfns
#standard dev

stddev<-function(set,sub,output,cond){
ds<-subset(set,set$tn==sub&set$condition==cond)
  sd(ds[,output],na.rm = T)  
}
s11<-stddev(d,"f","pitch","request")
s12<-stddev(d,"f","pitch","offer")
s13<-stddev(d,"f","pitch","doubt")
s14<-stddev(d,"f","pitch","critic")
s15<-stddev(d,"f","pitch","name")
s16<-stddev(d,"m","pitch","offer")
s17<-stddev(d,"m","pitch","critic")
s18<-stddev(d,"m","pitch","name")
s19<-stddev(d,"m","pitch","doubt")
s20<-stddev(d,"m","pitch","request")
pitchdf$SD_pitch_m<-c(s17,s19,s18,s20,s16)
pitchdf$SD_pitch_m<-round(pitchdf$SD_pitch_m,2)
pitchdf$SD_pitch_f<-c(s14,s13,s15,s11,s12)
pitchdf$SD_pitch_f<-round(pitchdf$SD_pitch_f,2)

s21<-stddev(d,"f","intensity","request")
s22<-stddev(d,"f","intensity","offer")
s23<-stddev(d,"f","intensity","doubt")
s24<-stddev(d,"f","intensity","critic")
s25<-stddev(d,"f","intensity","name")
s26<-stddev(d,"m","intensity","offer")
s27<-stddev(d,"m","intensity","critic")
s28<-stddev(d,"m","intensity","name")
s29<-stddev(d,"m","intensity","doubt")
s30<-stddev(d,"m","intensity","request")
pitchdf$SD_intensity_m<-c(s27,s29,s28,s30,s26)
pitchdf$SD_intensity_m<-round(pitchdf$SD_intensity_m,2)

pitchdf$SD_intensity_f<-c(s24,s23,s25,s21,s22)
pitchdf$SD_intensity_f<-round(pitchdf$SD_intensity_f,2)

sum_sd_m<-sum(pitchdf$SD_pitch_m)+sum(pitchdf$SD_intensity_m)
sum_sd_f<-sum(pitchdf$SD_pitch_f)+sum(pitchdf$SD_intensity_f)
difsum<-sum_sd_m-sum_sd_f

```

```{r tablemean, echo=F,warning=F}
kable(pitchdf[,1:4])
#kable(pitchdf[,5:8])
```
wir sehen im durchschnitt der werte, dasz der minimum pitch bei m/f bei der condition 'doubt' zu finden ist und an dieser condition auch die maximale intensity. maximum pitch und minimum intensity unterscheiden sich inter-speaker.

```{r tablesd, echo=F,warning=F}
kable(pitchdf[,5:8])
max_sd_p_m<-which.max(pitchdf$SD_pitch_m)
max_sd_p_f<-which.max(pitchdf$SD_pitch_f)
max_sd_i_m<-which.max(pitchdf$SD_intensity_m)
max_sd_i_f<-which.max(pitchdf$SD_intensity_f)



```
die standardabweichung ist bei pitch(m) mit `r pitchdf[max_sd_p_m,"SD_pitch_m"]` am höchsten bei `r rownames(pitchdf[max_sd_p_m,])` und bei pitch(f) mit `r pitchdf[max_sd_p_f,"SD_pitch_f"]` am höchsten bei `r rownames(pitchdf[max_sd_p_f,])`; für intensity gilt `r pitchdf[max_sd_i_m,"SD_intensity_m"]` bei `r rownames(pitchdf[max_sd_i_m,])`(m) und `r pitchdf[max_sd_i_f,"SD_intensity_f"]` bei `r rownames(pitchdf[max_sd_i_f,])`(f). die summen der standardabweichung (m)/(f) sind mit `r round(difsum,3)` punkten unterschied bei ~120 punkten ungefähr gleich.

```{r box_mpitch,echo=F,warning=F}
boxplot(b1,col=2,xlab="pitch M")
#par(new=T)
```

```{r box_fpitch,echo=F,warning=F}
boxplot(b2,col=2,xlab="pitch F")

```

```{r box_mintens,echo=F,warning=F}
boxplot(b3,col=3,xlab="intensity M")

```

```{r box_fintens,echo=F,warning=F}
boxplot(b4,col=3,xlab="intensity F")

```

