-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03-Week1_home.Rmd
95 lines (63 loc) · 2.52 KB
/
03-Week1_home.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Week 1 - Home
Open the data file LifeSat.sav.
```{r, message=FALSE, echo=FALSE}
library(foreign)
data <- read.spss("TCSM_student/LifeSat.sav", to.data.frame = TRUE)
knitr::opts_chunk$set(warning=FALSE, message=FALSE)
```
```{r, message=FALSE,eval=FALSE}
library(foreign)
data <- read.spss("LifeSat.sav", to.data.frame = TRUE)
```
### Question 1.a
Make a table with descriptive statistics for the variables: LifSat, educ, ChildSup, SpouSup, and age.
What is the average age in the sample? And the range (youngest and oldest child)?
*Hint: Use* `library(tidySEM); descriptives(); []`
<details>
<summary>Click for explanation</summary>
The package `tidySEM` contains a function to describe data. Install and load the package, then use the `descriptives()` function. Alternatively, you can also use the `describe()` function in the `psych` package.
```{r, echo = TRUE}
library(tidySEM)
descriptives(data[, c("LifSat", "educ", "ChildSup", "SpouSup", "age")])
```
<\details>
### Question 1.b
Perform a simple regression with LifSat as the dependent variable and educ as the independent variable.
*Hint: The function* `lm()` *(short for linear model) conducts linear regression. The functions* `summary()` *provides relevant summary statistics for the model. It can be helpful to store the results of your analysis in an object, too.*
<details>
<summary>Click for explanation</summary>
```{r, echo = TRUE}
results <- lm(LifSat ~ educ, data)
summary(results)
```
<\details>
### Question 1.c.
Do the same with age as the independent variable.
<details>
<summary>Click for explanation</summary>
```{r, echo = TRUE}
results <- lm(LifSat ~ age, data)
summary(results)
```
<\details>
### Question 1.d.
Again with ChildSup as the independent variable.
<details>
<summary>Click for explanation</summary>
```{r, echo = TRUE}
results <- lm(LifSat ~ ChildSup, data)
summary(results)
```
<\details>
### Question 1.e.
Perform a multiple regression with LifSat as the dependent variable and educ, age and ChildSup as the independent variables.
*Hint: You can use the + sign to add multiple variables to a model.*
<details>
<summary>Click for explanation</summary>
```{r, echo = TRUE}
results <- lm(LifSat ~ educ + age + ChildSup, data)
summary(results)
```
<\details>
### Question 1.f.
Compare the results under 1.e with those obtained under 1.b-1.d. What do you notice when you compare the regression parameter for each of the three predictors in the multiple regression with the corresponding regression parameters obtained in the simple regressions?