CS计算机代考程序代写 # BS1033 Lecture 1 Analysis Part 2

# BS1033 Lecture 1 Analysis Part 2
# Author: Chris Hansman
# Email: chansman@imperial.ac.uk
# Date : 07/01/19
# Installing Packages
#install.packages(“tidyverse”)

# Loading Libraries
library(tidyverse)

#Reading OLS Data
ols_basics<-read_csv("ols_basics.csv") #Scatter Plot of OLS Example Data ggplot(data = ols_basics ) + geom_point(aes(x = X, y = Y)) + ggsave("ols_scatter.pdf") #Scatter Plot of OLS Example Data with Regression Line ggplot(data = ols_basics ) + geom_point(aes(x = X, y = Y))+ geom_smooth( aes(x = X, y = Y), method='lm',formula=y~x) + ggsave("ols_scatter_regline.pdf") # Example Linear Regression ols_v1<-lm(Y~X, data= ols_basics) summary(ols_v1) #Scatter Plots for Non-Linear CEF with Regression Line: ggplot(data = ols_basics ) + geom_point(aes(x = X, y = Y_nl)) + geom_smooth( aes(x = X, y = Y_nl), method='lm',formula=y~x) + ggsave("ols_scatter_lfit_nl.pdf") #Reading S and P Data s_p_price<-read_csv("s_p_price.csv") s_p_price %>%
summarize(mean(price))

#Conditional Means for IT Sector:
s_p_price %>%
group_by(IT) %>%
summarize(mean_price = sprintf(“%0.3f”,mean(price)))

#Regressions for IT Sector:
ols_it<-lm(price~IT, data= s_p_price) summary(ols_it) #Conditional Means for All Sectors: s_p_price %>%
group_by(sector) %>%
summarize(mean_price = sprintf(“%0.3f”,mean(price)))

#Regressions for All Sectors:
ols_sector<-lm(price~as.factor(sector), data= s_p_price) summary(ols_sector)