Homework Assignment #1
1. Download Canadian monthly housing starts in urban centres over 10,000 (1950-now, total
dwellings) from CanSim and save it as tab-delimited txt file.
2. Start a R script with appropriate header and read in the txt data. Create a data frame with two
variables. The first one should include the dates (yyyy-mm) and the second one the
corresponding housing starts.
3. Create a histogram of the housing starts variable, comment on why it looks the way it looks and
if this is useful information.
4. Create a time series graph of housing starts, try to get the dates on the x-axis.
5. Create a function that takes in a vector x and calculates the growth rates (𝑙𝑛(𝑥𝑡) − 𝑙𝑛(𝑥𝑡−1)).
Within the function,
a. Determine the length of the input vector x and save it as n.
b. if the minimum element of the vector is negative, add the absolute value of this
minimum plus 1 to the vector, so that the new minimum is 1.
c. Take the natural logarithm of this new vector
d. Subtract the vector elements 1 to (n-1) from the vector elements 2 to n to get the
growth rates
e. Add an NaN to the beginning of the vector
f. Return the final vector
6. Create a vector v = [-2, 0, -1, 3, 5, 7, 12] and try out your function.
7. Apply your function to the housing starts variable.
8. Plot the new housing starts growth rates.
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。