If you are running R, connected to the internet, and have write privileges on your computer's disk, you can
install ldr by typing the following command in the R command window:
> install.packages("ldr")
To use the ldr package you must enter the library command in R:
> library(ldr)
Some Examples Using ldr
For more detail, see the manuscript about the ldr package.
Example 1: Covariance Reduction - CORE
# obtain the sample covariances
Sigmas <- list()
Sigmas[[1]] <- as.matrix(read.table(url("http://www.math.umbc.edu/~kofi/ldr/snake1.txt")))
Sigmas[[2]] <- as.matrix(read.table(url("http://www.math.umbc.edu/~kofi/ldr/snake2.txt")))
#Fit core through ldr using a simulated annealing procedure with GrassmannOptim; short = FALSE
fit <- ldr(Sigmas=Sigmas, ns=c(139, 90), numdir=4, model="core", short=FALSE, sim_anneal=TRUE, max_iter=500)
#Fit core through ldr using a simulated annealing procedure with GrassmannOptim; short = TRUE
fit1 <- ldr(Sigmas=Sigmas, ns=c(139, 90), numdir=2, model="core", verbose=TRUE, short=TRUE, sim_anneal=TRUE, max_iter=500)
summary(fit1)
Example 2: Likelihood Acquired Directions - LAD
data(flea)
X <- flea[,-1]
y <- as.integer(factor(flea[,1], levels=unique(flea[,1])))
fit <- ldr(X=as.matrix(X), y=y, numdir=3, model="lad", short=FALSE)
mycol <- y
mycol[mycol==1]<-"black"
mycol[mycol==2]<-"blue"
mycol[mycol==3]<-"green"
R <- t(fit$Gammahat[[3]])%*%t(X)
# Plotting the first two directions of the reductions
plot(R[1,], R[2,], xlab="LAD - Dir1", ylab="LAD - Dir2", pch=as.numeric(y), cex=1.50, col=mycol)
#-------------
data(bigmac)
fit <- ldr(X=bigmac[,-1], y=log(bigmac[,1]), ycat=FALSE, numdir=1, nslices=2, model="lad", short=TRUE, verbose=TRUE, sim_anneal=TRUE, max_iter=300)
summary(fit)
# Plotting the response against the reduction
plot(y, t(fit$Gammahat)%*%t(X), ylab="Sufficient Reduction", xlab="bigmac", cex=1.5)
Example 3: Principal Fitted Components - PFC
data(bigmac)
# Fit PFC with a piecewise constant basis with 5 slices and short=FALSE
fit <- ldr(X=bigmac[,-1], fy=bf(bigmac[,1], case="pdisc", degree=0, nslices=5), model="pfc", numdir=3, structure="aniso", short=FALSE)
summary(fit)
# Similar fit with short=TRUE
fit1 <- ldr(X=bigmac[,-1], fy=bf(bigmac[,1], case="pdisc", degree=0, nslices=5), model="pfc", numdir=2, structure="aniso", short=TRUE)
summary(fit1)
# Plotting the first direction of the reduction against the response
R <- t(fit1$Gammahat)%*%solve(fit1$Deltahat)%*%t(X)
plot(y, R[1,], ylab="Dir1 - PFC", xlab="bigmac", cex=1.5)
The views and opinions expressed in this page are strictly those of the page author.
The contents of this page have not been approved by the University of Maryland.