# Fit regression model
model <- lm(close ~ volume + time_years, data = df)
# Create grid for prediction
vol_seq <- seq(min(df$volume), max(df$volume), length.out = 30)
t_seq <- seq(min(df$time_years), max(df$time_years), length.out = 30)
grid <- expand.grid(volume = vol_seq, time_years = t_seq)
grid$close_pred <- predict(model, newdata = grid)
plot_ly() %>%
add_markers(
x = df$volume,
y = df$time_years,
z = df$close,
marker = list(size = 1),
name = "Observed Prices") %>%
layout(
scene = list(
xaxis = list(title = "Trading Volume"),
yaxis = list(title = "Time (years)"),
zaxis = list(title = "Closing Price")
)
)