#$$$$$$$$$$$$$$$$$$$$$ EXE 2.1 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# ################################################# #################### histogram #################### ################################################# # a histogram is useful to show the distribution of # a interval or continuous variable. This illustrates # whether the variable has a normal or other distribution # NOTE. this is not a test of normality! # you will use the dataset juul which can be found # by installing the package ISwR # create a histogram of igf1 (insuline growth factor) separate for boys and girls # make sure the graph looks as in the slides # test the normality # use functions 'skewness/kurtosis' # from package 'moments' # is the variable normally distributed? #$$$$$$$$$$$$$$$$$$$$$ EXE 2.2 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# ################################################# ############## recode variable ################ ################################################# # generate factor: # transform age into a factor with three categories # 1: pre puberty (up to 11) # 2: puberty (years 11-17) # 3: post puberty (18 and older) # attach this recoded variable to juul # use function 'factor' and 'cut' # check with summary # how many people are in puberty in the sample? # use recoded variable age that you created above ################################################# ################### barplot ################### ################################################# # create a barplot of gender # add color using argument 'col' # create a stacked barplot of the recoded age distribution # for boys and girls separately # use same colors # what is the mean level of igf1 for boys and girls for age 15 until 16? # use function 'tapply' #$$$$$$$$$$$$$$$$$$$$$ EXE 2.3 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# ################################################# ################### z-score ################### ################################################# # create a function that calculates the z-score of a variable # check with function 'scale' ########################################################### ################### standard deviation ################### ########################################################### # calculate the standard deviation of both age and igf1 in juul # using a for loop # use different names for your objects as are known to R (i.e. mean, sd etc)