[R] R^2, AICc, bootstrap CIs for Orthogonal regression

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sat Aug 22 11:10:17 CEST 2020


Dear R-experts,

I have fitted an orthogonal regression and have some difficulties to get the adjusted R^2 and R^2, the AICc, the coefficients and R^2 bootstrap confidence intervals. Here below my R codes.
Many thanks for your precious help.

########################
y=c(231,212,112,143,154,165,134,115,167,154,134,123,145,167,169,123,132,143,123,165)
x1=c(9,4,5,3,2,1,2,3,4,5,3,6,8,11,2,1,4,3,2,6)
x2=c(9.8,4.2,1.4,2.3,4.3,5.4,2.4,1.1,1.3,6.4,7.5,4.5,2.2,3.3,3.7,3.4,2.1,4.5,3.3,2.2)

####Fit orthogonal regression
install.packages("pracma")
library(pracma)
a=matrix(c(x1,x2),ncol=2)
fit1=odregress(a,y)
fit1 

####R.squared
fit1[["r.squared"]]
fit1[["adj.r.squared"]]

####AICc
install.packages("AICcmodavg")
library(AICcmodavg)
AICc(fit1)

####Bootstrap CIs (coefficients and R^2)
install.packages("boot")
library(boot)
# function to obtain regression...
bs <- function(formula, data, indices) {
  d <- data[indices,] # allows boot to select sample
  fit <- odregress(formula, data=d)
  return(coef(fit))
}
# bootstrapping with 1000 replications
results <- boot(data=Dataset, statistic=bs,
   R=1000)
########################



More information about the R-help mailing list