Question

In: Computer Science

***This problem must be done using R so please provide the R code used to find...

***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.***

The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one of the three treatment groups: control, diet and diet plus exercise. The variables in the data set are given below.

*** This is the question:

Construct a histogram for the baseline weights of these 34 individuals. Then elaborate thoroughly on your findings from the histogram created about the distribution of the baseline weights (e.g., center (three central tendencies), spread, skewness, existence of outliers, etc). ***

***Here is the rest of the data needed to solve the problem. Please solve using R. Thank you!***

ID   group   wl1   wl2   wl3   se1   se2   se3   bw
1   Control   3.3   2.9   2.5   13.9   13.3   15.5   127.5
2   Control   3.8   3.9   3.8   13.2   14.1   16.5   130.7
3   Control   4.2   3.4   -0.5   17   12   15.7   129.6
4   Control   3.4   0.9   0.6   11.2   11.1   11.5   134.4
5   Control   6.1   1.8   1.2   15.8   15   12.5   130.6
6   Control   7   6.6   3.6   15.9   17   18.2   131.6
7   Control   5.9   2.9   5.2   17.1   16.2   19.6   127.1
8   Control   6.4   4   0.9   13.3   14.8   15.3   133.6
9   Control   3.2   2.9   1.2   13.5   14.6   14.3   125.9
10   Control   3.6   3.3   2.3   13.4   16.1   12.6   128.2
11   Control   3.5   3   1.4   15.8   15.4   10.1   130.4
12   Control   6.3   -0.1   -0.4   14.7   13.3   16.6   130.5
13   Diet   5.6   3.9   1.7   12.2   11.1   13.8   129
14   Diet   6.3   4   1.1   13.1   13.7   14.5   133.7
15   Diet   7   4.7   4   17.5   11.3   18.4   130.6
16   Diet   4.1   2.1   1.7   16.8   15.4   17.9   129.9
17   Diet   2.6   2.7   0.7   16   17   14.2   128.1
18   Diet   3.3   4.8   5.6   13   10.9   18   132.6
19   Diet   4.2   3.2   0.2   12.1   10.5   14   125.4
20   Diet   5.9   2.8   1.4   11.8   10.7   11.1   141.6
21   Diet   3.7   6.7   2.4   16.9   15.9   19.2   127.8
22   Diet   8   5.9   4.4   19   18.9   18.7   133.8
23   Diet   2.6   2.4   0.5   15.1   15.5   15.3   131.3
24   Diet   8.8   5.4   2.5   16.1   13.9   17.4   133.9
25   DietEx   8.4   6.1   3.7   14.9   11.9   19.7   125.9
26   DietEx   3.2   5.8   2   16   11.8   17.7   127.8
27   DietEx   8.7   6.5   2.5   12.9   12.8   17.2   126.4
28   DietEx   2.9   6.4   1.3   16.4   13.1   17.3   131.2
29   DietEx   2.6   4.2   0.6   13   12.5   15.9   124.2
30   DietEx   8.6   5.4   1.1   14.7   12.3   17.2   131.2
31   DietEx   6.1   4.8   3.7   14.9   13   17.8   129.5
32   DietEx   8.3   3.8   1.5   15.7   13.8   16.7   138.8
33   DietEx   7.6   8.7   5.3   16.1   16.4   18.8   129.3
34   DietEx   8.2   7.4   1.4   17.4   17.3   17.4   129.4

Solutions

Expert Solution

Desired R -Code is given below:


#You can do it directly by entering the data, name the data frame as df, then all commands will work
library(readxl)
df<- read_excel("C:/Users/91773/Desktop/data.xlsx")
df
wl_sum<-df$wl1+df$wl2+df$wl3
df<-cbind(df,wl_sum)
# total wl column added to last of the data frame
df
#Sorted order
# negative sign used to order in decreasing order
df<-df[order(-df$wl_sum),]
df
#Box-plot using ggplot2 package---install if you don't have
graphics.off()
library(ggplot2)
ggplot(df,aes(group,wl_sum),fill=wl_sum)+geom_boxplot()+stat_summary(fun="mean",color="red",shape=15)


R-Output


> #You can do it directly by entering the data, name the data frame as df, then all commands will work
> library(readxl)
> df<- read_excel("C:/Users/91773/Desktop/data.xlsx")
> df
# A tibble: 34 x 9
ID group wl1 wl2 wl3 se1 se2 se3 bw
<dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 Control 3.3 2.9 2.5 13.9 13.3 15.5 128.
2 2 Control 3.8 3.9 3.8 13.2 14.1 16.5 131.
3 3 Control 4.2 3.4 -0.5 17 12 15.7 130.
4 4 Control 3.4 0.9 0.6 11.2 11.1 11.5 134.
5 5 Control 6.1 1.8 1.2 15.8 15 12.5 131.
6 6 Control 7 6.6 3.6 15.9 17 18.2 132.
7 7 Control 5.9 2.9 5.2 17.1 16.2 19.6 127.
8 8 Control 6.4 4 0.9 13.3 14.8 15.3 134.
9 9 Control 3.2 2.9 1.2 13.5 14.6 14.3 126.
10 10 Control 3.6 3.3 2.3 13.4 16.1 12.6 128.
# ... with 24 more rows
> wl_sum<-df$wl1+df$wl2+df$wl3
> df<-cbind(df,wl_sum)
> # total wl colun added to last of the data frame
> df
ID group wl1 wl2 wl3 se1 se2 se3 bw wl_sum
1 1 Control 3.3 2.9 2.5 13.9 13.3 15.5 127.5 8.7
2 2 Control 3.8 3.9 3.8 13.2 14.1 16.5 130.7 11.5
3 3 Control 4.2 3.4 -0.5 17.0 12.0 15.7 129.6 7.1
4 4 Control 3.4 0.9 0.6 11.2 11.1 11.5 134.4 4.9
5 5 Control 6.1 1.8 1.2 15.8 15.0 12.5 130.6 9.1
6 6 Control 7.0 6.6 3.6 15.9 17.0 18.2 131.6 17.2
7 7 Control 5.9 2.9 5.2 17.1 16.2 19.6 127.1 14.0
8 8 Control 6.4 4.0 0.9 13.3 14.8 15.3 133.6 11.3
9 9 Control 3.2 2.9 1.2 13.5 14.6 14.3 125.9 7.3
10 10 Control 3.6 3.3 2.3 13.4 16.1 12.6 128.2 9.2
11 11 Control 3.5 3.0 1.4 15.8 15.4 10.1 130.4 7.9
12 12 Control 6.3 -0.1 -0.4 14.7 13.3 16.6 130.5 5.8
13 13 Diet 5.6 3.9 1.7 12.2 11.1 13.8 129.0 11.2
14 14 Diet 6.3 4.0 1.1 13.1 13.7 14.5 133.7 11.4
15 15 Diet 7.0 4.7 4.0 17.5 11.3 18.4 130.6 15.7
16 16 Diet 4.1 2.1 1.7 16.8 15.4 17.9 129.9 7.9
17 17 Diet 2.6 2.7 0.7 16.0 17.0 14.2 128.1 6.0
18 18 Diet 3.3 4.8 5.6 13.0 10.9 18.0 132.6 13.7
19 19 Diet 4.2 3.2 0.2 12.1 10.5 14.0 125.4 7.6
20 20 Diet 5.9 2.8 1.4 11.8 10.7 11.1 141.6 10.1
21 21 Diet 3.7 6.7 2.4 16.9 15.9 19.2 127.8 12.8
22 22 Diet 8.0 5.9 4.4 19.0 18.9 18.7 133.8 18.3
23 23 Diet 2.6 2.4 0.5 15.1 15.5 15.3 131.3 5.5
24 24 Diet 8.8 5.4 2.5 16.1 13.9 17.4 133.9 16.7
25 25 DietEx 8.4 6.1 3.7 14.9 11.9 19.7 125.9 18.2
26 26 DietEx 3.2 5.8 2.0 16.0 11.8 17.7 127.8 11.0
27 27 DietEx 8.7 6.5 2.5 12.9 12.8 17.2 126.4 17.7
28 28 DietEx 2.9 6.4 1.3 16.4 13.1 17.3 131.2 10.6
29 29 DietEx 2.6 4.2 0.6 13.0 12.5 15.9 124.2 7.4
30 30 DietEx 8.6 5.4 1.1 14.7 12.3 17.2 131.2 15.1
31 31 DietEx 6.1 4.8 3.7 14.9 13.0 17.8 129.5 14.6
32 32 DietEx 8.3 3.8 1.5 15.7 13.8 16.7 138.8 13.6
33 33 DietEx 7.6 8.7 5.3 16.1 16.4 18.8 129.3 21.6
34 34 DietEx 8.2 7.4 1.4 17.4 17.3 17.4 129.4 17.0
> #Sorted order
> # negative sign used to order in decreasing order
> df<-df[order(-df$wl_sum),]
> df
ID group wl1 wl2 wl3 se1 se2 se3 bw wl_sum
33 33 DietEx 7.6 8.7 5.3 16.1 16.4 18.8 129.3 21.6
22 22 Diet 8.0 5.9 4.4 19.0 18.9 18.7 133.8 18.3
25 25 DietEx 8.4 6.1 3.7 14.9 11.9 19.7 125.9 18.2
27 27 DietEx 8.7 6.5 2.5 12.9 12.8 17.2 126.4 17.7
6 6 Control 7.0 6.6 3.6 15.9 17.0 18.2 131.6 17.2
34 34 DietEx 8.2 7.4 1.4 17.4 17.3 17.4 129.4 17.0
24 24 Diet 8.8 5.4 2.5 16.1 13.9 17.4 133.9 16.7
15 15 Diet 7.0 4.7 4.0 17.5 11.3 18.4 130.6 15.7
30 30 DietEx 8.6 5.4 1.1 14.7 12.3 17.2 131.2 15.1
31 31 DietEx 6.1 4.8 3.7 14.9 13.0 17.8 129.5 14.6
7 7 Control 5.9 2.9 5.2 17.1 16.2 19.6 127.1 14.0
18 18 Diet 3.3 4.8 5.6 13.0 10.9 18.0 132.6 13.7
32 32 DietEx 8.3 3.8 1.5 15.7 13.8 16.7 138.8 13.6
21 21 Diet 3.7 6.7 2.4 16.9 15.9 19.2 127.8 12.8
2 2 Control 3.8 3.9 3.8 13.2 14.1 16.5 130.7 11.5
14 14 Diet 6.3 4.0 1.1 13.1 13.7 14.5 133.7 11.4
8 8 Control 6.4 4.0 0.9 13.3 14.8 15.3 133.6 11.3
13 13 Diet 5.6 3.9 1.7 12.2 11.1 13.8 129.0 11.2
26 26 DietEx 3.2 5.8 2.0 16.0 11.8 17.7 127.8 11.0
28 28 DietEx 2.9 6.4 1.3 16.4 13.1 17.3 131.2 10.6
20 20 Diet 5.9 2.8 1.4 11.8 10.7 11.1 141.6 10.1
10 10 Control 3.6 3.3 2.3 13.4 16.1 12.6 128.2 9.2
5 5 Control 6.1 1.8 1.2 15.8 15.0 12.5 130.6 9.1
1 1 Control 3.3 2.9 2.5 13.9 13.3 15.5 127.5 8.7
11 11 Control 3.5 3.0 1.4 15.8 15.4 10.1 130.4 7.9
16 16 Diet 4.1 2.1 1.7 16.8 15.4 17.9 129.9 7.9
19 19 Diet 4.2 3.2 0.2 12.1 10.5 14.0 125.4 7.6
29 29 DietEx 2.6 4.2 0.6 13.0 12.5 15.9 124.2 7.4
9 9 Control 3.2 2.9 1.2 13.5 14.6 14.3 125.9 7.3
3 3 Control 4.2 3.4 -0.5 17.0 12.0 15.7 129.6 7.1
17 17 Diet 2.6 2.7 0.7 16.0 17.0 14.2 128.1 6.0
12 12 Control 6.3 -0.1 -0.4 14.7 13.3 16.6 130.5 5.8
23 23 Diet 2.6 2.4 0.5 15.1 15.5 15.3 131.3 5.5
4 4 Control 3.4 0.9 0.6 11.2 11.1 11.5 134.4 4.9
> #Box-plot using ggplot2 package---install if you don't have
> graphics.off()
> library(ggplot2)
> ggplot(df,aes(group,wl_sum),fill=wl_sum)+geom_boxplot()+stat_summary(fun="mean",color="red",shape=15)
Obtained Box-Plot

Interpretation:

From the box plot it is clear that Diet with exercise shown the best result of weight loss while control shows the least effect in comparison diet and DietEx.


Related Solutions

***This problem must be done using R so please provide the R code used to find...
***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.*** The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one...
Part 2– R work (must be done in R) Copy and paste your R code and...
Part 2– R work (must be done in R) Copy and paste your R code and output into a word document, along with your written answers to the questions, and upload to Canvas.   Follow these instructions to import the necessary dataset: Before opening the dataset needed for this problem, you’ll need to call the “car”package.  Run the following line of code: > library(car) Now you can import the “Prestige” dataset and use it to answer the question below. Name the data...
*Please provide r studio code/file* 1) Find the equation of the best fit line using least...
*Please provide r studio code/file* 1) Find the equation of the best fit line using least squares linear fit of x,y: set.seed(88) x <- 1:100 y <- jitter(1.5*x+8,amount=10) 2) For question 1, Draw the P=0.95 prediction intervals for y when x=1:150 3) For question 1, Find the equation of the best fit line using median-based linear fit of x,y. 4) For question 3, draw the P=0.95 prediction interval for y # when x=1:150
R work (must be done in R) Before opening the dataset needed for this problem, you’ll...
R work (must be done in R) Before opening the dataset needed for this problem, you’ll need to call the “car” package. Run the following line of code: > library(car)  Now you can import the “ Cowles” dataset and use it to answer the question below. Name the data frame with your EID: > my_eid <- Cowles Remember to include any code you use along with your answers in your submission! 3. Cowles and Davis (1987) collected data on...
Please Provide R code as well Use R to find probability (p-value). Find probability P(X>12.3), where...
Please Provide R code as well Use R to find probability (p-value). Find probability P(X>12.3), where X follows F-distribution with degree of freedom in numerator 4 and degree of freedom in numerator 10.
needs to be done in C++ Q6. Coding Question (you must code this problem and submit...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit via Blackboard): Keep everything as Integers. Row and Column Numbering starts at 1. Equation for each Cell :   Coll = (Row * Col * 10) Using Nested Loops display the following exactly as it is shown below:                                  Columns % Brand         1           2         3          4               A            10         20       30       40          B            20         40        60       80           C            30         60        90    ...
Do the following using R. You must also turn in a copy of your R code....
Do the following using R. You must also turn in a copy of your R code. (10) What is the probability a beta (1, 8) random variable is less than 0.13? (11) What is the probability a beta (3, 9) random variable is greater than .4? (12) What is the probability a beta (18,4.4) random variable is between 0.6 and 0.7? (13) At what value of x is the probability that a beta (4, 7) random varable is less than...
Complete the R code using Rstudio so that it calculates and returns the estimates of β,...
Complete the R code using Rstudio so that it calculates and returns the estimates of β, the intercept and regression weight of the logistic regression of approximate GPA on Rouder-Srinivasan preference. ## Data Preference <- c( 0, 0, 0, 0, 0, 1, 1, 1, 1) # 0: Rouder; 1: Srinivasan GPA <- c(2.0, 2.5, 3.0, 3.5, 4.0, 2.5, 3.0, 3.5, 4.0) Count <- c( 4, 5, 21, 22, 8, 2, 1, 4, 7) # Define the deviance function deviance <-...
The Book of R (Question 20.2) Please answer using R code. Continue using the survey data...
The Book of R (Question 20.2) Please answer using R code. Continue using the survey data frame from the package MASS for the next few exercises. The survey data set has a variable named Exer , a factor with k = 3 levels describing the amount of physical exercise time each student gets: none, some, or frequent. Obtain a count of the number of students in each category and produce side-by-side boxplots of student height split by exercise. Assuming independence...
This is done by using Angular in Visual code: Can you please give examples of the...
This is done by using Angular in Visual code: Can you please give examples of the following? 1. Use Math.random function to generate a number between 20 and 100 and then use the ngSwitch directive to display a letter grade based on this class grading policy. a. add implements OnInit to the AppComponent class b. add variable x in the AppComponent class c. add ngOnInit(){ this.x = Math.floor(Math.random()*10);} d. add {{x}} in the app.components.html file e. You should see numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT