วันพฤหัสบดีที่ 2 กุมภาพันธ์ พ.ศ. 2560

Week2 Matrix Notation

Matrix Notation Exercises

Matrix Notation Exercises #1

1/1 point (graded)
In R we have vectors and matrices. You can create your own vectors with the function c.
c(1,5,3,4)
They are also the output of many functions such as
rnorm(10)
You can turn vectors into matrices using functions such as rbindcbind or matrix.
Create the matrix from the vector 1:1000 like this:
X = matrix(1:1000,100,10)
  correct 
225
225 
Explanation
X[25,3]
 
You have used 1 of 5 attempts
Correct (1/1 point)

Matrix Notation Exercises #2

1/1 point (graded)
Using the function cbind, create a 10 x 5 matrix with first column x=1:10. Then columns 2*x, 3*x, 4*x and 5*x in columns 2 through 5.
  correct 
105
 
Explanation
x = 1:10
X=cbind(x, 2*x, 3*x, 4*x, 5*x)
sum(X[7,])
 
You have used 1 of 5 attempts
Correct (1/1 point)

Matrix Notation Exercises #3

1/1 point (graded)
Which of the following creates a matrix with multiples of 3 in the third column?
Explanation
You can make each of the matrices in R and examine them visually. Or you can check whether the third column has all multiples of 3 with all(X[,3]%%3==0). Note that the fourth choice does not even have a 3rd column.

PH525.2xWeek1Introduction to Linear Models

Introduction Exercises

Introduction Exercises #1

1 point possible (graded)
If you haven't done so already, install the library UsingR
install.packages("UsingR")
Then once you load it you have access to Galton's father and son heights:
library(UsingR)
data("father.son",package="UsingR")


Explanation
mean(father.son$sheight)
 

Introduction Exercises #2

1 point possible (graded)
One of the defining features of regression is that we stratify one variable based on others. In Statistics we use the verb "condition". For example, the linear model for son and father heights answers the question how tall do I expect a son to be if I condition on his father being x inches. The regression line answers this question for any x.
Using the father.son dataset described above, we want to know the expected height of sons if we condition on the father being 71 inches. Create a list of son heights for sons that have fathers with heights of 71 inches (round to the nearest inch).
What is the mean of the son heights for fathers that have a height of 71 inches (don't round off your answer)? (Hint: use the function round() on the fathers' heights)

 

Explanation
mean(father.son$sheight[round(father.son$fheight)==71])
or using dplyr:
library(dplyr)
filter(father.son,round(fheight)==71) %>% summarize(mean(sheight))

Introduction Exercises #3

1/1 point (graded)
We say a statistical model is a linear model when we can write it as a linear combination of parameters and known covariates plus random error terms. In the choices below, Y represents our observations, time t is our only covariate, unknown parameters are represented with letters a,b,c,d and measurment error is represented by the letter e. Note that if t is known, then any transformation of t is also known. So, for example, both Y=a+bt +e and Y=a+b f(t) +e are linear models. Which of the following can't be written as a linear model?

Introduction Exercises #4

0/1 point (graded)
Supposed you model the relationship between weight and height across individuals with a linear model. You assume that the height of individuals for a fixed weight x follows a liner model Y = a + b x + e. Which of the following do you feel best describes what e represents?

Explanation
Remember the model is across individuals and we fix x. People of the same height can vary greatly in other aspects of their physiology: for example different bone density or differing amounts of muscle and fat.