Question

Completing regression modeling can require various steps in order to obtain the best results. The process can involve creating a graph to illustrate the relationship between variables, determining best-fit lines, and also approximating or producing smooth-fit lines to represent the data. What are the necessary commands required to carry out such an analysis in R? Please provide an example to illustrate your assertions.

Answer #1

Consider, the Rest program given below,

# Create the predictor and response variable.

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)

y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

relation <- lm(y~x)

# Give the chart file a name.

png(file = "linearregression.png")

# Plot the chart.

plot(y,x,col = "blue",main = "Height & Weight Regression",

abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in cm")

# Save the file.

dev.off()

This will give you plot of x and y as given below and by observing this plot one can easily test the fit.

Thank you.

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 18 minutes ago

asked 46 minutes ago

asked 51 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago