#Name the data as montly_sec_only
sum(is.na(c(monthly_sec_only$Partyname, monthly_sec_only$Bmunit)))
library(dplyr)
library(tidyr)
library(reshape2)
library(fBasics)
library(stats)
library(car)
t <- select(monthly_sec_only, Partyname, Bmunit)
t1 <- t[!duplicated(t),]
arrange(t1, Partyname)
num <- table(t1$Partyname)
sort(num, decreasing=TRUE)
p <- data.frame(monthly_sec_only$Month , monthly_sec_only$B_Sec, monthly_sec_only$Sec_Mwh, stringsAsFactors = FALSE)
p <- arrange(p, monthly_sec_only$Month)
p0 <- na.omit(p)
dim(p)
dim(p0)
#There are 10 missing values
list <- which(rowSums(is.na(p)) !=0)
p_na <- p[list, ]
p_na
names(p0)
p0 <- rename (p0, Month = "monthly_sec_only.Month", Bid = "monthly_sec_only.B_Sec", Volume = "monthly_sec_only.Sec_Mwh")
names(p0)
Month <- group_by(p0, Month)
s <- sum(p0[ ,2])
sec_price <- summarize(Month, secprice = sum(Bid * Volume / s))
price <- ts(sec_price$secprice, frequency = 12 , start = c(2005,11))
plot(price, xlab = 'Year', ylab = '(Secondary)Volume Weighted Average Price', main = 'Monthly Price Line', type = 'l')
##Create a new chart of pence per KWh of coal, oil and gas from chart "Quarterly" and extract column A,B,D,F,G
##Impoer the refined data from another working sheet called "input price"
coal_gas_prices <- read_excel("D:/JHU/Career/1/coal_gas_prices.xls", sheet = "Input Price")
View(coal_gas_prices)
names(coal_gas_prices)
input_prices <- coal_gas_prices[ ,3:5]
head(input_prices)
sec <- read_excel("D:/JHU/Career/1/coal_gas_prices.xls", sheet = "Sec")
sec$qt <- rep(1:16, each = 3)
input_prices$qt <- rownames(input_prices)
sec3 <- merge(sec, input_prices)
sec3 <- select(sec3,secprice:Gas)
sec3 <- sec3[-1, ]
head(sec3)
View(sec_price)
fit <- lm (secprice ~ . , data=sec3)
summary (fit) $coefficient
#R-square equals to 0.1195 and adjusted R-square equals to 0.05804, which is acceptable #The probility tells us that the price of caol, oil and gas all have significant statistical impacts on the level of 5% #Which means a $0.5 decrease in the coal price would lead to a $1 rise in the second price; a $0.03, $0.1 increase in the oil and gas price could lead to a $1 rise in the second price
vif(fit)
#VIf less than 10, which means there is no multicollinearity