Assignment-4

pdf

School

Concordia University *

*We aren’t endorsed by this school

Course

280

Subject

Mechanical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

16

Uploaded by edfffr

Report
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 1/16 Assignment 4 2024-02-26 #Consider the islands vector discussed in this section. #1 (a) Compare the histograms that result when using breaks based on Sturges’ and Scott’s rules. # Make this comparison on the log-scale and on the original scale. par(mfrow=c(2,2)) hist(islands, breaks = "Sturges", main = "Sturges") hist(islands, breaks = "Scott", main = "Scott") hist(log(islands), breaks = "Sturges", main = "Sturges on log scale") hist(log(islands), breaks = "Scott", main = "Scott on log scale") b. Construct a normal QQ plot, and compare the result with the plots in Figure 3.13; which one is most similar, and what does this tell you about this data set? qqnorm(islands, main = ""); qqline(islands)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 2/16 #most similar to "D is skewed to the right", this tells us that the mean is more positiv e than the median c. Construct a boxplot for these data on the log-scale as well as the original scale. par(mfrow=c(1,2)) boxplot(islands, main = "Original scale") boxplot(log(islands), main = "Log scale")
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 3/16 (d) Construct a dot chart of the areas. Is a log transformation needed here? par(mfrow=c(1,2)) dotchart(islands,main="Original scale") dotchart(log(islands),main="Log scale")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 4/16 e. Which form of graphic do you think is most appropriate for display- ing these data? dotchart(sort(log(islands)), main = "Log scale, sorted")
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 5/16 #3 Consider the pressure data frame. There are two columns— temperature and pressure. (a) Construct a scatterplot with pressure on the vertical axis and temperature on the horizontal axis. Are the variables related linearly or nonlinearly? plot(pressure ~ temperature, data = pressure)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 6/16 (b) The graph of the following function passes through the plotted points reasonably well: y = (0.168 + 0.007x)20/3. The differences between the pressure values predicted by the curve and the observed pressure values are called residuals. Here is a way to calculate them: residuals <- with(pressure, pressure - (0.168 + 0.007*temperature)ˆ(20/3)) Construct a normal QQ plot of these residuals and decide whether they are normally distributed or whether they follow a skewed distribution. residuals<- with(pressure,pressure-(0.168+0.007*temperature)^(20/3)) qqnorm(residuals); qqline(residuals)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 7/16 #They follow a left skewed distribution c. Now, apply the power transformation y3/20 to the pressure data values. Plot these transformed values against temperature. Is a linear or nonlinear relationship evident now? plot(pressure^(3/20) ~ temperature, data = pressure)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 8/16 #Linear relationship evident d. Calculate residuals for the difference between transformed pressure values and those predicted by the straight line. Obtain a normal QQ plot, and decide whether the residuals follow a normal distribution or not. predicted_transformed <- (0.168 + 0.007 * pressure$temperature)^(20/3) transformed_pressure <- pressure$pressure^(3/20) residuals_transformed <- transformed_pressure - predicted_transformed qqnorm(residuals_transformed) qqline(residuals_transformed)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 9/16 #it doesn't follow a normal distribution #Sec3.3 #4 Re-do the plots of Figure B.4, but this time, apply the six graphics functions to a variable X which is defined by X = Z2, where Z is a simulated standard normal random variable as in the example. Comment on the changes that you see in the plots. (The variable X is an example of a chi-squared random variable on 1 degree of freedom.) par(list = list(mfrow = c(3, 2), mar = c(2.5,2.1,0.1,0.1))) Z <- rnorm(1000) X=Z^2 hist(X, main = "") hist(X, breaks = "Freedman-Diaconis", main = "") plot(density(X), main = "") boxplot(X) qqnorm(X, main = ""); qqline(X) ts.plot(X)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 10/16 #Due to Z^2, the negative values became positive therefore in the graphs we can see the graph is positive skewed and became more dense #5 Refer to the previous question. Construct another set of six plots as in Figure B.4, but this time apply the data in EuStockMarkets (i.e. apply the code of B.4 to Z where Z <- EuStockMarkets). Comment on the results, and use the summary() function to gain further insight. Which of the six plots are useful descriptors of this data set, and which may be limited in their usefulness? Z <- EuStockMarkets summary(Z) ## DAX SMI CAC FTSE ## Min. :1402 Min. :1587 Min. :1611 Min. :2281 ## 1st Qu.:1744 1st Qu.:2166 1st Qu.:1875 1st Qu.:2843 ## Median :2141 Median :2796 Median :1992 Median :3247 ## Mean :2531 Mean :3376 Mean :2228 Mean :3566 ## 3rd Qu.:2722 3rd Qu.:3812 3rd Qu.:2274 3rd Qu.:3994 ## Max. :6186 Max. :8412 Max. :4388 Max. :6179
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 11/16 par(list = list(mfrow = c(3, 2), mar = c(2.5,2.1,0.1,0.1))) Z <- EuStockMarkets hist(Z, main = "") hist(Z, breaks = "Freedman-Diaconis", main = "") plot(density(Z), main = "") boxplot(Z) qqnorm(Z, main = ""); qqline(Z) ts.plot(Z) #Since the dataset is the price of stocks throughout the years, the boxplot and the time series plot seem useful for the give data. Boxplot allows us to analyze the quantiles, m ean, median, min and max. Time series plot allows us to have an insight of the value of each stock throughout the years. Histograms, qqplots and normal plots dont seem that use ful in analyzing stock prices. #Sec3 #2 Consider the pressure data frame again. (a) Plot pressure against temperature,and use the following com- mand to pass a curve through these data: curve((0.168 + 0.007*x)ˆ(20/3), from = 0, to = 400, add = TRUE) plot(pressure$temperature,pressure$pressure) curve((.168+.007*x)^(20/3),0,400,add = TRUE)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 12/16 (b) Now, apply the power transformation y3/20 to the pressure data values. Plot these transformed values against temperature. Is a linear or nonlinear relationship evident now? Use the abline() function to pass a straight line through the points. (You need an intercept and slope for this—see the previous part of this question to obtain appropriate values.) transformed_pressure <- pressure$pressure^(3/20) plot(transformed_pressure ~ temperature, data = pressure) abline(0.168,.007)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 13/16 #Because from the curve in part a, it is clear that for the best fitted straight line, t he #intercept will be .168 and the slope will be .007 c. Add a suitable title to the graph. plot(transformed_pressure ~ temperature, data = pressure, main="Transformed pressure vs Temperature")
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 14/16 d. Re-do the above plots,but use the mfrow() function to display them in a 2 × 1 layout on the graphics page. Repeat once again using a 1 × 2 layout. par(mfrow=c(2,1)) plot(pressure$temperature,pressure$pressure) curve((.168+.007*x)^(20/3),0,400) abline(0.168,.007)
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 15/16 par(mfrow=c(1,2)) plot(pressure$temperature,pressure$pressure) curve((.168+.007*x)^(20/3),0,400)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2/26/24, 12:18 PM Assignment 4 file:///Users/kevinwang/Downloads/Assignment4.html 16/16