Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
84 views
in Technique[技术] by (71.8m points)

How can I add an error term to my bootstrap regression in R?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...