Professional Documents
Culture Documents
seed(421)
mtcars
str(mtcars)
wt=mtcars$wt
disp=(mtcars$disp-mean(mtcars$disp))/sd(mtcars$disp)
mpg=mtcars$mpg
traindata=cbind(wt,disp,mpg)
library(scatterplot3d)
scatterplot3d(wt, # x axis
disp, # y axis
mpg, # z axis
type="h",
color="red",
main="3-D Scatterplot",
xlab="Weight",
ylab="Displacement",
zlab="Mpg")
y=mpg
# calculate w
return(w)
w<-mvl_regression(x,y)
print(w)
print(x)
print(y)
estimate=x%*%w
library(scatterplot3d)
s3d<-scatterplot3d(wt, # x axis
disp, # y axis
mpg, # z axis
type="h",
color="red",
main="3-D Scatterplot",
xlab="Weight",
ylab="Displacement",
zlab="Mpg"
s3d$points3d(wt,disp,estimate,col='blue' ,type='l',lwd=1)
A=cbind(x,wt^2,disp^2)
print(A)
w_plnm<-mvl_regression(A,y)
print(w_plnm)
estimate_plnm=A%*%w_plnm
s3d$points3d(wt,disp,estimate_plnm,col='green' ,type='l',lwd=1)
result=cbind(y,estimate,estimate_plnm)
mean_squared_linear=sum((y-estimate)^2)/length(y)
rms_linear=sqrt(mean_squared_linear)
mean_squared_plnm=sum((y-estimate_plnm)^2)/length(y)
rms_plnm=sqrt(mean_squared_plnm)