DATA101_lab4soln_2022WT1

pdf

School

University of British Columbia *

*We aren’t endorsed by this school

Course

101

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

8

Uploaded by DukeGrouse2352

Report
The University of British Columbia Irving K. Barber Faculty of Science DATA 101 001/002 Lab Questions Practice Solution. In each question below, write out (or type) the required lines of R code, together with the answer to the question. 1. Copy the file income.R to a folder on your computer. This file contains median total family income for a number of Ontario cities by year. 2. Construct the following graph. income <- read.table ( 'income.R' , header = TRUE ) rownames (income) <- income[, 1 ] income <- as.matrix (income[, - 1 ]) dotchart (income, xlab = 'Total median income ($1000s)' , cex = .7 ) mtext ( 'Year' , side = 2 , line = 1.5 , las = 2 , at = 22 ) title ( 'Family Income in Ontario Cities' ) 1
2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 Ottawa Toronto London Windsor Sudbury ThunderBay 65 70 75 80 85 90 Total median income ($1000s) Year Family Income in Ontario Cities 3. Can you make higher lever graph base on what you did for the prviouse question? If so, show your work. colorNO <- as.numeric ( rownames (income)) - 2004 dotchart (income, xlab = 'Total median income ($1000s)' , lcolor =colorNO, color =colorNO, cex = .7 ) mtext ( 'Year' , side = 2 , line = 1.5 , las = 2 , at = 22 , col =colorNO) title ( 'Family Income in Ontario Cities' ) 2
2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 2005 2006 2007 2008 2009 Ottawa Toronto London Windsor Sudbury ThunderBay 65 70 75 80 85 90 Total median income ($1000s) Year Year Year Year Year Family Income in Ontario Cities 4. Copy the file windmill.txt (windmill data) to a folder on your computer. This file contains observations on wind velocity and the corresponding DC electrical output. (a) Construct a graph which effectively displays the information in this data set. windmill <- read.table ( "windmill.txt" , header = TRUE ) plot (windmill, main = "Wind Velocity and DC Electrical Output" ) 3
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
4 6 8 10 0.5 1.0 1.5 2.0 Wind Velocity and DC Electrical Output Velocity Output (b) Find the best fit line for electrical output is produced by the wind velocity. And add this line in the plot you draw in previous question. windmill.lm <- lm (Output ~ Velocity, data =windmill) summary (windmill.lm) ## ## Call: ## lm(formula = Output ~ Velocity, data = windmill) ## ## Residuals: ## Min 1Q Median 3Q Max ## -0.59869 -0.14099 0.06059 0.17262 0.32184 ## ## Coefficients: 4
## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 0.13088 0.12599 1.039 0.31 ## Velocity 0.24115 0.01905 12.659 7.55e-12 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 0.2361 on 23 degrees of freedom ## Multiple R-squared: 0.8745,Adjusted R-squared: 0.869 ## F-statistic: 160.3 on 1 and 23 DF, p-value: 7.546e-12 plot (windmill, main = "Wind Velocity and DC Electrical Output" ) abline (windmill.lm) 4 6 8 10 0.5 1.0 1.5 2.0 Wind Velocity and DC Electrical Output Velocity Output 5. Copy the file cuckoos.txt (cuckoo eggs data) to a folder on your computer. This file contains observations on the lengths and breadths of cuckoo eggs left in the nests of 5
various other bird species. Construct the following two sets of graphs. Note that in the second set of graphs, the respective lines are least-squares lines obtained using the lm() function. cuckoos <- read.table ( 'cuckoos.txt' , header = TRUE ) par ( mfrow = c ( 1 , 2 ), pty = 's' ) cuckoos <- cuckoos[ order (cuckoos $ species),] boxplot (length ~ species, data =cuckoos, axes = FALSE , ylim = c ( 19.5 , 25 ), ylab = 'length (mm)' , cex.lab = .75 ) title ( 'Cuckoo Egg Lengths' ) box () axis ( side = 2 , at = seq ( 20 , 25 , 1 ), label = seq ( 20 , 25 , 1 ), las = 2 , cex.axis = .75 ) labels1 <- unique (cuckoos $ species)[ c ( 1 , 4 , 6 )] labels2 <- unique (cuckoos $ species)[ c ( 2 , 5 )] labels3 <- unique (cuckoos $ species)[ c ( 3 )] mtext (labels1, side = 1 , at = c ( 1 , 4 , 6 ), cex = .75 , line = 0 ) mtext (labels2, side = 1 , at = c ( 2 , 5 ), cex = .75 , line = 1 ) mtext (labels3, side = 1 , at = c ( 3 ), cex = .75 , line = 0.5 ) boxplot (breadth ~ species, data =cuckoos, axes = FALSE , ylim = c ( 13.5 , 19 ), ylab = 'breadth (mm)' , cex.lab = .75 ) title ( 'Cuckoo Egg Breadths' ) box () axis ( side = 2 , at = seq ( 14 , 19 , 1 ), label = seq ( 14 , 19 , 1 ), las = 2 , cex.axis = .75 ) labels1 <- unique (cuckoos $ species)[ c ( 1 , 4 , 6 )] labels2 <- unique (cuckoos $ species)[ c ( 2 , 5 )] labels3 <- unique (cuckoos $ species)[ c ( 3 )] mtext (labels1, side = 1 , at = c ( 1 , 4 , 6 ), cex = .75 , line = 0 ) mtext (labels2, side = 1 , at = c ( 2 , 5 ), cex = .75 , line = 1 ) mtext (labels3, side = 1 , at = c ( 3 ), cex = .75 , line = 0.5 ) 6
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
species length (mm) Cuckoo Egg Lengths 20 21 22 23 24 25 hedge.sparrow robin wren meadow.pipit tree.pipit pied.wagtail species breadth (mm) Cuckoo Egg Breadths 14 15 16 17 18 19 hedge.sparrow robin wren meadow.pipit tree.pipit pied.wagtail 7
20 21 22 23 24 25 15.0 16.0 17.0 hedge.sparrow breadth 20 21 22 23 24 25 15.0 16.0 17.0 meadow.pipit breadth 20 21 22 23 24 25 15.0 16.0 17.0 pied.wagtail breadth 20 21 22 23 24 25 15.0 16.0 17.0 robin breadth 20 21 22 23 24 25 15.0 16.0 17.0 tree.pipit breadth 20 21 22 23 24 25 15.0 16.0 17.0 wren breadth 8