I want to create a linear regression by adding an error term to a bootstrap
I want to see how many times each car has the lowest predicted mpg
df <- mtcars
This is my function but I want to incorporate an error term to the predicted value so I don't have the same output in each run
I found that could be an error term like residuals or normal error rate
I am using the rank function to see how many time each car has the lowest value of mpg
I split the data because I want to test this approach outside of my sample to see if gives accurate results or not.
splitData <- resample_partition(df, c(test = 0.3, train=0.7))
observ.lm <- lm(mpg~., data = splitData$train)
da = df[sample(nrow(df), replace=TRUE),]
bootpred = function(data){
da = da[sample(nrow(da), replace=TRUE),]
fit = observ.lm
rank(predict(fit,data))
}
predictions = data.frame(replicate(10, bootpred(splitData$test)))
question from:
https://stackoverflow.com/questions/66045653/how-can-i-add-an-error-term-to-my-bootstrap-regression-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…