Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.50 KB | None | 0 0
  1. ########## Funkce pro konstrukci tabulky souhrnných charakteristik (cz)################################
  2. souhrn.stat=function(values,groups,sign.digits,digits.in) {
  3. # values ... datový vektor (vektor typu Numeric)
  4. # groups ... skupiny (vektor typu Factor)
  5. # sign.digits ... počet des. míst, na něž se zaokrouhlují vypočtené souhrnné statistiky
  6. # digits.in ... počet des. míst složek datového vektoru
  7.  
  8. # Výpočet charakteristik
  9. rozsah=tapply(values,groups,function(x) sum(!is.na(x)))
  10. minimum=tapply(values,groups,min,na.rm=TRUE)
  11. dolni.kv=tapply(values,groups,quantile,probs=0.25,na.rm=TRUE)
  12. prumer=tapply(values,groups,mean,na.rm=TRUE)
  13. median=tapply(values,groups,quantile,probs=0.5,na.rm=TRUE)
  14. horni.kv=tapply(values,groups,quantile,probs=0.75,na.rm=TRUE)
  15. maximum=tapply(values,groups,max,na.rm=TRUE)
  16. smer.odch=tapply(values,groups,sd,na.rm=TRUE)
  17. var.koef=100*smer.odch/prumer
  18. sikmost=tapply(values,groups,skewness,na.rm=TRUE)
  19. spicatost=tapply(values,groups,kurtosis,na.rm=TRUE)
  20. hradby.min=dolni.kv-1.5*(horni.kv-dolni.kv)
  21. hradby.max=horni.kv+1.5*(horni.kv-dolni.kv)
  22.  
  23. # Zaokrouhlení charakteristik
  24. dolni.kv=formatC(dolni.kv,digits=sign.digits, format="f")
  25. prumer=formatC(prumer,digits=sign.digits, format="f")
  26. median=formatC(median,digits=sign.digits, format="f")
  27. horni.kv=formatC(horni.kv,digits=sign.digits, format="f")
  28. smer.odch= formatC(smer.odch,digits=sign.digits, format="f")
  29. var.koef= formatC(var.koef,digits=1, format="f")
  30. sikmost= formatC(sikmost,digits=3, format="f")
  31. spicatost= formatC(spicatost,digits=3, format="f")
  32. hradby.min= formatC(hradby.min,digits=digits.in+1, format="f")
  33. hradby.max= formatC(hradby.max,digits=digits.in+1, format="f")
  34.  
  35. # Sloučení výsledků do tabulky (rbind ... slučuje řádky)
  36. souhrn=rbind(rozsah,minimum,dolni.kv,prumer,median,horni.kv,maximum,smer.odch,var.koef,sikmost,spicatost,hradby.min,hradby.max)
  37. # Definování popisků řádků tabulky
  38. souhrn.popis=c("rozsah","minimum","dolní kvartil","průměr","medián","horní kvartil","maximum","směrodatná odchylka","variační koeficient (%)","šikmost","špičatost","dolní mez (vnitřní hr.)","horní mez (vnitřní hr.)")
  39. rownames(souhrn)=souhrn.popis
  40.  
  41. # Definování výstupu funkce
  42. return(souhrn)}
  43.  
  44. ##########################################################################################################
  45.  
  46. # Generování tabulky souhrnných statistik s využitím funkce souhrn.stat
  47. souhrn.po_zak=souhrn.stat(values=data_po_zak$po_zak,groups=data_po_zak$vyrobce,sign.digits=3,digits.in=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement