#$$$$$$$$$$$$$$$$$$$$$ EXE 3.1 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# ################################################# ################## plot line #################### ################################################# # first calculate the coefficients (beta, intercept) # for the model where the dependent variable horsepower (hp) # is related to the independent variable miles per gallon (mpg) # from dataset mtcars # plot the two variables # add the line based on the estimates that you calculated # above ################################################# ################## assess fit ################### ################################################# # calculate the fit of the model above # check with 'lm' function # look up function ?lm # calculate R2 #$$$$$$$$$$$$$$$$$$$$$ EXE 3.2 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$# ################################################# ################## dummy vars ################### ################################################# # dummy variables have two levels like gender # to test differences between men and women # in an interval variable you can use a linear # model or a t-test. # in this exercise you will do both to see # how these solutions are comparable. # try to interpret the coefficients as # discussed during the lecture. # use dataset juul (see last lecture) # conduct first linear regression to # explain igf1 (insuline growth factor) by sex # then compare with t.test # use var.equal=TRUE # calculate the t-value by hand # use var / sd and nrow / length function # check your solution with t.test # do the same for the independent student's t-test ################################################# ################## interval var ################# ################################################# # relate age to igf1 (both interval variables) # plot the variables # add the regression line # what do you see? ############################################################## ################### t-test function ########################## ############################################################## # for those who want to practice functions: # to calculate the t-test, you need the # means and standard deviations, and observed N # use vectorized commands (work with vectors instead # of looping over i) # create function to conduct t-test on one variable # group should be variable with 2 levels (1,2) # use complete names, i.e. including the dataframe ttest<-function(variable, group){ # 1. create groups # 2. exclude missings # 3. calculate p value # 4. return values } ttest(... , ...) # check with t.test function