02-08-2026

The Creation of a Demonstratable Dataframe

First Start by using the set.seed function to create repeatable results.

set.seed(728)

Create the number of repetitions.

n <- 100

Gather all whole values between 1 and the number of repetitions.

x <- 1:n

Create a vector to store the slow consistent decent.

decent <- (-0.5 * x) + 100

Using the rnorm function of r to then vary each point by a set value, in this case 10.

noise <- rnorm(n, mean = 0, sd = 10)

By combining the decent and noise we now have a scatter plot in which the trend needs to be found.

y <- decent + noise

Finally putting both the vector x and y to a dataframe to create a workable base.

df <- data.frame(Time = x, Value = y)

Model Creation

A simple linear regression model is at its core just a function that relates a dependant (y) to the independant (x).

The most simple and desired form is slope intercept form y = mx + b.

To find an average slope one must use the equation m = (y2-y1)/(x2-x1).

m = (67.82656 - 87.54516) / (57 - 16)

m = -19.7186 / 41

m = -0.48094146341

y2= (-0.48094146341 * x) + 100

Then I take this value and attach it to the existing dataframe.

df$Value2 <- y2

The Creation of a Demonstratable Dataframe Once More

The seed

set.seed(537)

Create the number of repetitions.

n <- 1000

Gather all whole values between 1 and the number of repetitions.

x <- 1:n

Create a vector to store the faster and longer decent

decent <- (-0.8 * x) + 500

Using the rnorm function of r to then vary each point by a set value, this time it will be 150.

noise <- rnorm(n, mean = 0, sd = 150)

By combining the decent and noise we now have another scatter plot to divise the trend of .

y <- decent + noise

Finally putting both the vector x and y to a dataframe to create a workable base.

df <- data.frame(Time = x, Value = y)

Proper Model Creation

The less simple but much more correct simple linear regression model is at the function that relates a dependant (y) to the independant (x) including the margin of error (e).

Written as y = a+ Bx + e

Unlike the slope intercept form this requires the Sum of Squared Errors.

\[𝑓(𝑎,𝑏)=\sum_{i=0}^{n} [𝑦_i−(𝑎+𝑏𝑥_𝑖)]^2\] Instead of doing this by hand I will instead use the built in functions

model <- lm(y ~ x, data = df)
summary(model)
sigma(model)

## 
## Call:
## lm(formula = y ~ x, data = df)
## 
## Coefficients:
## (Intercept)            x  
##    496.9094      -0.7978

Once More in With ggplot

Once More in With Plotly