Introduction to R and Basic Models

What is R and RStudio?

R is a programming language designed for data analysis and visualization. RStudio is a development environment that makes working with R easier.

Installing Packages

To use additional functionalities:

#install.packages("ggplot2")
#install.packages("dplyr")
library(ggplot2)
library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Data Import

Load data from a CSV file:

# Import Energy Market Prices
data <- read.csv("Energy Market Prices.csv")
head(data)
##   Temperature Electricity_Price
## 1        25.3             125.3
## 2        27.1             130.1
## 3        22.4             118.7
## 4        23.7             120.2
## 5        26.5             128.6
## 6        20.9             115.4

Simple Linear Regression

Explore the relationship between interest rates and bond prices:

# Fitting regression model
model <- lm(Temperature ~ Electricity_Price, data = data)
summary(model)
## 
## Call:
## lm(formula = Temperature ~ Electricity_Price, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.59039 -0.22382 -0.02211  0.17845  0.61113 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       -24.794594   1.136356  -21.82   <2e-16 ***
## Electricity_Price   0.398365   0.009184   43.37   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2991 on 28 degrees of freedom
## Multiple R-squared:  0.9853, Adjusted R-squared:  0.9848 
## F-statistic:  1881 on 1 and 28 DF,  p-value: < 2.2e-16
# Visualizar resultados
plot(data$Temperature, data$Electricity_Price, main = "Bond Price vs Interest Rate")
abline(model, col = "red")

The regression model examines the relationship between Electricity Price and Temperature.

Impact of Independent Variable: A positive coefficient suggests that higher electricity prices correlate with higher temperatures (or vice versa if negative), but correlation does not imply causation.

Limitations: The model may overlook other influencing factors, assume a linear relationship, and ignore seasonal trends.

Improvements: Adding more variables, checking for non-linearity, and using advanced models (e.g., multiple regression, machine learning) can enhance accuracy.