-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst.r
17 lines (15 loc) · 813 Bytes
/
first.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
x <- c(1,2,3,4,5,6) # Create ordered collection (vector)
y <- x^2 # Square the elements of x
print(y) # print (vector) y
mean(y) # Calculate average (arithmetic mean) of
# (vector) y; result is scalar
var(y) # Calculate sample variance
lm_1 <- lm(y ~ x) # Fit a linear regression model
# "y = f(x)" or "y = B0 + (B1 * x)"
# store the results as lm_1
print(lm_1) # Print the model from the (linear model
# object) lm_1
summary(lm_1) # Compute and print statistics for the fit
# of the (linear model object) lm_1
par(mfrow=c(2, 2)) # Request 2x2 plot layout
plot(lm_1) # Diagnostic plot of regression model