) %>%
gather(scenario, aggregate_demand, -output)
data_frame(
output = output,
equilibrium = output,
before = get_aggregate_demand(government_spending),
after = get_aggregate_demand(new_government_spending)
) %>%
gather(scenario, aggregate_demand, -output) %>%
qplot(~output, ~aggregate_demand, color = ~scenario, data = .)
qplot(output, aggregate_demand, color = scenario, data = data) +
layer_lines()
data =
data_frame(
output = output,
equilibrium = output,
before = get_aggregate_demand(government_spending),
after = get_aggregate_demand(new_government_spending)
) %>%
gather(scenario, aggregate_demand, -output)
qplot(output, aggregate_demand, color = scenario, data = data) +
layer_lines()
ggplot(data) +
aes(x = output, y = aggregate_demand, color = scenario) +
layer_lines()
ggplot(data) +
aes(x = output, y = aggregate_demand, color = scenario) +
geom_line()
ggplot(data) +
aes(x = money, y = interest_rate, color = scenario) +
geom_line()
income = 50000
interest_rate = 0.15
get_money = function(income, interest_rate)
income * (0.65 - interest_rate)
money = get_money(income, interest_rate)
money
new_income = income * (1 + .2)
new_interest_rate = 0.65 - money / new_income
new_interest_rate
interest_rate = seq(0, 0.65, by = 0.01)
data =
data_frame(
interest_rate,
before = get_money(income, interest_rate),
after = get_money(new_income, interest_rate)
) %>%
gather(scenario, money, -interest_rate)
ggplot(data) +
aes(x = money, y = interest_rate, color = scenario) +
geom_line()
autonymous_consumption = 200
marginal_propensity_to_consume = 0.7
autonymous_investment = 100
marginal_propensity_to_invest = 0.1
FED_power = 200
government_spending = 200
taxes = 200
target_interest_rate = 0.2
multiplier = 1 /
(1 - marginal_propensity_to_consume - marginal_propensity_to_invest)
get_output = function(government_spending, interest_rate) {
autonymous_demand =
autonymous_consumption -
marginal_propensity_to_consume * taxes +
autonymous_investment +
government_spending
multiplier * autonymous_demand - multiplier * FED_power * interest_rate
}
output = get_output(government_spending, target_interest_rate)
output
get_money_supply = function(output, interest_rate)
4 * output - 10000 * interest_rate
get_money_supply(output, target_interest_rate)
get_consumption = function(income)
autonymous_consumption + marginal_propensity_to_consume * (output - taxes)
consumption = get_consumption(output)
consumption
get_investment = function(income, interest_rate)
autonymous_investment + marginal_propensity_to_invest * output - FED_power * target_interest_rate
investment = get_investment(output, interest_rate)
investment
consumption + investment + government_spending
new_target_interest_rate = target_interest_rate * (1 - 0.1)
output_2 = get_output(government_spending, new_target_interest_rate)
output_2
get_money_supply(output_2, new_target_interest_rate)
get_consumption(output_2)
get_investment(output_2, new_target_interest_rate)
new_government_spending = 160
output_3 = get_output(new_government_spending, target_interest_rate)
get_consumption(output_3)
get_investment(output_3, new_target_interest_rate)
interest_rates = seq(0, 0.3, 0.01)
data =
data.frame(
interest_rate = interest_rates,
IS = get_output(government_spending, interest_rates),
IS_new = get_output(new_government_spending, interest_rates)
) %>%
gather(line, output, -interest_rate)
ggplot(data) +
aes(x = interest_rate, y = output, color = line) +
geom_line()
View(data)
IS_data = data.frame(
interest_rate = interest_rates,
IS = get_output(government_spending, interest_rates),
IS_new = get_output(new_government_spending, interest_rates)
)
LS_data = data_frame(
output = c(
0, 1,
0, 1
),
interest_rate = c(
target_interest_rate, target_interest_rate,
new_target_interest_rate, new_target_interest_rate
),
line = c(
"LM1", "LM1",
"LM2", "LM2"
)
LS_data = data_frame(
LS_data = data.frame(
output = c(
0, 1,
0, 1
),
interest_rate = c(
target_interest_rate, target_interest_rate,
new_target_interest_rate, new_target_interest_rate
),
line = c(
"LM1", "LM1",
"LM2", "LM2"
)
)
data =
cbind(IS_data, LS_data)
LS_data = data.frame(
output = c(
0, 1,
0, 1
),
interest_rate = c(
target_interest_rate, target_interest_rate,
new_target_interest_rate, new_target_interest_rate
),
line = c(
"LM1", "LM1",
"LM2", "LM2"
)
)
LS_data = data.frame(
output = (0, 1),
LS_data = data.frame(
output = c(0, 1),
LM = target_interest_rate,
LM2 = new_target_interest_rate
)
data = cbind(
gather(IS_data, line, interest_rate, -output)
gather(IS_data, line, output, -interest_rate)
data = cbind(
gather(IS_data, line, interest_rate, -output),
gather(IS_data, line, output, -interest_rate)
)
gather(IS_data, line, interest_rate, -output)
LS_data = data.frame(
output = c(0, 1), # two points for a line
LM = target_interest_rate,
LM2 = new_target_interest_rate
)
LM_data = data.frame(
output = c(0, 1), # two points for a line
LM = target_interest_rate,
LM2 = new_target_interest_rate
)
gather(LM_data, line, interest_rate, -output)
data = cbind(
gather(LM_data, line, interest_rate, -output),
gather(IS_data, line, output, -interest_rate)
)
gather(LM_data, line, interest_rate, -output)
z = gather(LM_data, line, interest_rate, -output)
View(z)
z1 = gather(IS_data, line, output, -interest_rate)
View(z1)
IS_data = data.frame(
interest_rate = interest_rates,
IS = get_output(government_spending, interest_rates),
IS_new = get_output(new_government_spending, interest_rates)
)
LM_data = data.frame(
output = c(0, 1), # two points for a line
LM = target_interest_rate,
LM_new = new_target_interest_rate
)
data = rbind(
gather(LM_data, line, interest_rate, -output),
gather(IS_data, line, output, -interest_rate)
)
ggplot(data) +
aes(x = interest_rate, y = output, color = line) +
geom_line()
target = data_frame(
money = c(0, 40000),
interest_rate = 0.15,
scenario = "target"
)
target = data_frame(
money = c(0, 40000), # two points for a line
interest_rate = 0.15,
scenario = "target"
)
ggplot(rbind(data, target)) +
aes(x = money, y = interest_rate, color = scenario) +
geom_line()
rbind(data, target)
data =
data_frame(
interest_rate,
before = get_money(income, interest_rate),
after = get_money(new_income, interest_rate)
) %>%
gather(scenario, money, -interest_rate)
target = data_frame(
money = c(0, 40000), # two points for a line
interest_rate = 0.15,
scenario = "target"
)
rbind(data, target)
read.csv("C:/Users/Carrie/.julia/dev/SplitApplyCombine/help_me.csv")
read.csv("C:/Users/Carrie/.julia/hp/SplitApplyCombine/help_me.csv")
result = read.csv("C:/Users/dev/.julia/dev/SplitApplyCombine/help_me.csv")
pwd()
result = read.csv("C:/Users/hp/.julia/dev/SplitApplyCombine/help_me.csv")
result = read.csv("C:/Users/hp/.julia/dev/SplitApplyCombine/help_me.csv")
View(result)
sum(is.na(result))
length(result)
size(result)
sum(is.na(result)) / 992490
install.packages("Rssa")
library(Rssa)
install.packages(c("backports", "BH", "colorspace", "curl", "data.table", "dplyr", "ggplot2", "haven", "httpuv", "jsonlite", "knitr", "lme4", "markdown", "pander", "pillar", "plm", "quantreg", "Rcpp", "RcppEigen", "readr", "readxl", "rio", "rlang", "rmarkdown", "shiny", "tibble", "tidyr", "tinytex"))
library(Rssa)
install.packages("forecast")
install.packages("forecast")
library(Rssa)
result = read.csv("C:/Users/hp/.julia/dev/SplitApplyCombine/help_me.csv")
View(result)
ssa
?ssa
library(Rssa)
?ssa
library(Rssa)
result = read.csv("C:/Users/hp/.julia/dev/SplitApplyCombine/help_me.csv")
library(dplyr)
quarter_hours_per_year = round(365.25 * 24 * 4)
quarter_hours_per_day = 24 * 4
test =
result %>%
mutate(
n = 1:n(),
year_fraction = n %% quarter_hours_per_year,
day_fraction = n %% quarter_hours_per_day
)
more =
test %>%
group_by(day_fraction) %>%
summarize(daily_mean_discharge = mean(discharge, na.rm = TRUE)) %>%
left_join(test) %>%
mutate(minus_daily_discharge = discharge - daily_mean_discharge)
View(more)
more =
test %>%
group_by(day_fraction) %>%
summarize(daily_mean_discharge = mean(discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_discharge = discharge - daily_mean_discharge)
View(more)
test =
result %>%
mutate(
n = 1:n(),
year_fraction = n %% quarter_hours_per_year,
day_fraction = n %% quarter_hours_per_day
)
more =
test %>%
group_by(day_fraction) %>%
summarize(daily_mean_discharge = mean(discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_discharge = discharge - daily_mean_discharge)
v =
more %>%
group_by(year_fraction) %>%
summarize(yearly_mean_discharge = mean(minus_daily_discharge, na.rm = TRUE)) %>%
mutate(
year_sequence = 1:n(),
smooth_yearly_mean_discharge =
predict(loess(yearly_mean_discharge ~ year_sequence, span = 0.3))
) %>%
right_join(more) %>%
mutate(
residual_flow = minus_daily_discharge - yearly_mean_discharge
)
plot(v$daily_mean_discharge[1:quarter_hours_per_day])
plot(v$residual_flow[1:quarter_hours_per_day])
plot(v$discharge[1:quarter_hours_per_day])
sidual_flow
plot(v$residual_flow[1:quarter_hours_per_day])
plot(v$residual_flow[1:quarter_hours_per_day*10])
plot(v$residual_flow[1:(quarter_hours_per_day*10)])
plot(v$discharge[1:(quarter_hours_per_day*10)])
residual_flow
plot(v$residual_flow[1:(quarter_hours_per_day*10)])
plot(v$discharge[1:(quarter_hours_per_day*10)])
more =
test %>%
mutate(log_discharge = log(discharge))
View(more)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction) %>%
summarize(daily_log_mean_discharge = mean(log_discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_log_discharge = log_discharge - daily_mean_log_discharge)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction
)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction) %>%
summarize(daily_log_mean_discharge = mean(log_discharge, na.rm = TRUE))
test =
result %>%
mutate(
log_discharge = log(discharge),
n = 1:n(),
year_fraction = n %% quarter_hours_per_year,
day_fraction = n %% quarter_hours_per_day
)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction) %>%
summarize(daily_log_mean_discharge = mean(log_discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_log_discharge = log_discharge - daily_mean_log_discharge)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction) %>%
summarize(daily_mean_log_discharge = mean(log_discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_log_discharge = log_discharge - daily_mean_log_discharge)
more =
test %>%
mutate(log_discharge = log(discharge)) %>%
group_by(day_fraction) %>%
summarize(daily_mean_log_discharge = mean(log_discharge, na.rm = TRUE)) %>%
right_join(test) %>%
mutate(minus_daily_log_discharge = log_discharge - daily_mean_log_discharge)
v =
more %>%
group_by(year_fraction) %>%
summarize(yearly_mean_log_discharge = mean(minus_daily_log_discharge, na.rm = TRUE))
plot(v$yearly_mean_log_discharge)
v =
more %>%
group_by(year_fraction) %>%
summarize(yearly_mean_log_discharge = mean(minus_daily_log_discharge, na.rm = TRUE)) %>%
mutate(
year_sequence = 1:n(),
smooth_yearly_mean_log_discharge =
predict(loess(yearly_mean_log_discharge ~ year_sequence, span = 0.3))
)
plot(v$smooth_yearly_mean_log_discharge)
v =
more %>%
group_by(year_fraction) %>%
summarize(yearly_mean_log_discharge = mean(minus_daily_log_discharge, na.rm = TRUE)) %>%
mutate(
year_sequence = 1:n(),
smooth_yearly_mean_log_discharge =
predict(loess(yearly_mean_log_discharge ~ year_sequence, span = 0.3))
) %>%
right_join(more) %>%
mutate(
residual_log_discharge = minus_daily_log_discharge - smooth_yearly_mean_log_discharge
)
plot(v$discharge[1:(quarter_hours_per_day*10)])
plot(v$residual_log_discharge[1:(quarter_hours_per_day*10)])
plot(v$residual_log_discharge)
plot(v$log_discharge)
sum(v$log_discharge)
sum(v$residual_log_discharge)
sum(v$residual_log_discharge, na.rm)
sum(v$residual_log_discharge, na.omit = TRUE)
sum(v$residual_log_discharge, na.rm = TRUE)
sum(v$log_discharge, na.rm = TRUE)
residual_
sum((v$residual_log_discharge)^2, na.rm = TRUE)
library(nycflights13)
write.csv(weather, "weather.csv")
write.csv(planes, "planes.csv")
write.csv(airlines, "airlines.csv")
library(nycflights13)
write.csv(airports, "airports.csv")
library(nycflights13)
library(nycflights13)
flights
result = flights
View(result)
library(dplyr)
result =
flights %>%
group_by(tailnum)
View(result)
result =
flights %>%
arrange(flight)
View(result)
flight
View(result)
?arrange
result =
flights %>%
arrange(desc(distance)
)
View(result)
airlines
test = airlines
View(test)
test = airports
View(test)
test = weather
View(test)
weather
weather
View(test)
test =
weather %>%
select(-year, -month, -day, -hour)
View(test)
test =
weather %>%
select(-year, -month, -day, -hour) |>
rename(datetime = time_hour)
test =
weather %>%
select(-year, -month, -day, -hour) %>%
rename(datetime = time_hour)
View(test)
write.csv
?write.csv
write.csv(weather, "weather.csv", row.names = FALSE)
write.csv(planes, "planes.csv", row.names = FALSE)
write.csv(weather, "weather.csv", row.names = FALSE)
write.csv(planes, "planes.csv", row.names = FALSE)
write.csv(airlines, "airlines.csv", row.names = FALSE)
write.csv(airports, "airports.csv", row.names = FALSE)
write.csv(flights, "flights.csv", row.names = FALSE)
pwd()
getwd()
View(result)
write.csv(airports, "airports.csv", row.names = FALSE)
library(nycflights13)
write.csv(airports, "airports.csv", row.names = FALSE)
pwd()
getwd()
library(nycflights13)
airports$tzone
airports$tzone == "\\N"
sum(airports$tzone == "\\N")
library(rex)
install.packages("rex")
library(rex)
rex(except_some_of(".", "/", " ", "-"))
library(nycflights13)
library(devtools)
library(nycflights)
setwd("C:/Users/hp/.julia/dev/LightQuery/test")
write.csv(airports, "airports.csv", na = "", row.names = FALSE)
nrows(flights)
airports
flights
?write.csv
flights[1:2]
flights[1:2, :]
flights[1:2,]
write.csv(airports, "airports.csv", na = "", row.names = FALSE)
write.csv(flights[1:1000,], "flights.csv", na = "", row.names = FALSE)
write.csv(airports, "airports.csv", na = "", row.names = FALSE)
library(nycflights13)
setwd("C:/Users/hp/.julia/dev/LightQuery/test")
write.csv(airports, "airports.csv", na = "", row.names = FALSE)
write.csv(flights[1:1000,], "flights.csv", na = "", row.names = FALSE)
write.csv(flights, "flights.csv", na = "", row.names = FALSE)
write.csv(flights[1:1000], "flights.csv", na = "", row.names = FALSE)
write.csv(flights[1:1000,], "flights.csv", na = "", row.names = FALSE)
write.csv(flights, "flights.csv", na = "", row.names = FALSE)
write.csv(flights, "weather.csv", na = "", row.names = FALSE)
write.csv(weather, "weather.csv", na = "", row.names = FALSE)
?weather
