Simple linear regression and prediction in R ,with validation of model

preview_player
Показать описание
#simplelinearregression #rprogramming #

This video discusses linear regression and prediction using R programming, for the analysis of biochemical assay results.

Download the csv file and store in your working directory, as shown in video

# import the data
setwd("H:/Rworks/R training/linear regression") # set your working directory and save data file in that directory.
head(df)
str(df)
attach(df)
plot(conc,abs)

# split the data
index= sample(1:nrow(df), round(0.8*nrow(df),0),replace=FALSE)

train= df[index,]
test=df[-index, ]

dim(train)
dim(test)

# fit model
lm_mod = lm(abs~conc,train)
lm_mod
summary(lm_mod)

plot(lm_mod)
# validate the model
pred = predict(lm_mod,test)
pred

test$pred=pred
test

# visualize the predcited and actual vlaues
library(ggplot2)
ggplot(test,aes(x=conc))+
geom_point(aes(y=abs),color="red")+
geom_point(aes(y=pred),color="blue")
Рекомендации по теме
welcome to shbcf.ru