Please turn-in a hard copy of your R code along with a brief write-up of the sol
ID: 3589739 • Letter: P
Question
Please turn-in a hard copy of your R code along with a brief write-up of the solutions. Also submit via blackboard a copy of your R code.(if you can also download it on blackboard).
Please turn-in a hard copy of your R code along with a brief write-up of the solutions. Also submit via blackboard a copy of your R code.(if you can also download it on blackboard).
2. In the following data with 12 subjects, the first column is a sex indicator (1=male and 0=female) the second column is a treatment indicator (1=treatment and 0=placebo) and the remaining columns are the recorded outcome at three follow-up visits.
ID
Sex
Treatment
T.1
T.2
T.3
1
0
0
94
23
61
2
0
1
46
92
97
3
0
0
40
65
43
4
0
1
64
15
8
5
0
0
6
34
59
6
0
1
30
37
10
7
1
0
47
85
88
8
1
1
36
41
3
9
1
0
92
60
95
10
1
1
1
100
47
11
1
0
32
66
62
12
1
1
25
43
93
(a) Enter the data into R using two methods you know.
(b) Reshape the data from wide format to long format so that the repeated measures are on separates rows.
(c) Plot the above data using xyplot() in the lattice package. Use separate plotting symbols for treatment and plot males and females on diff t panels. Create a clean fi with a legend, meaningful labels and meaningful axes. (Hint: use factor variables)
ID
Sex
Treatment
T.1
T.2
T.3
1
0
0
94
23
61
2
0
1
46
92
97
3
0
0
40
65
43
4
0
1
64
15
8
5
0
0
6
34
59
6
0
1
30
37
10
7
1
0
47
85
88
8
1
1
36
41
3
9
1
0
92
60
95
10
1
1
1
100
47
11
1
0
32
66
62
12
1
1
25
43
93
Explanation / Answer
Part a-
# assuming data is available in CSV file
# Reading CSV file in R Method 1
patient_data <- read.table(“c:/patient.csv”, header = TRUE, sep = “,”)
# Reading CSV file in R Method 2
patient_data2 <- read.csv(“c:/patient.csv”, header = TRUE, sep = “,”)
Part b-
# using patient_data data frame for reshaping data
# reshaping data to long format
library(reshape2) # package is used for data transformation
# using melt function we can convert the wide data to long format
patient_data_long <- melt(patient_data, id.vars=c(“Sex”, “Treatment”),
+ variable.name = (“Measurement_variable”), value.name = (“Measurement_value”)
Part c-
# using patient_data data frame for creating graph
library(lattice) # importing lattice package for xyplot function
xyplot(treatment ~ T.1 | sex, patient_data, grid = TRUE, group = treatment,
+ main = “T.1 Treatment Male and Female”, xlab = “Treatment”, ylab= “Values”)