## Least square approximation. This version Oct 19, 2006 ## Reference Wang, H. and Leng, C. (2007) ## ## Written by Hansheng Wang ## Comments and suggestions are welcome ## ## README: lsa() takes the fitted oject (e.g., from lm(), ## glm(), coxph(), rq(), etc) as its only input and ## find the optimal estimator according to AIC or BIC. ## In order to make lsa() useful, the corresponding ## R object should at least implement coef() and vcov() ## functionalities. lsa() uses this to extract the ## coefficients and its covariance matrix estimate. source("LSA.R") #load the LSA code #LSA with linear model library(lars) #load the lars package data(diabetes) #load the diabetes data lm.obj=lm(y~x,data=diabetes) #fit linear model lsa.obj=lsa(lm.obj) #find LSA estimator #LSA with logistic regression library(glmpath) #load glmpath package data(heart.data) #load the heart data glm.obj=glm(y~x, family=binomial,data=heart.data) #fit logistic regression lsa.obj=lsa(glm.obj) #find LSA estimator #LSA with Cox's model library(survival) #load survival library data(lung) #load lung data lung$status=lung$status-1 #create censor indicator lung$sex=lung$sex-1 #creat gender dummy cox.obj=coxph(Surv(time,status)~age+sex+ph.ecog+ph.karno+pat.karno+meal.cal+wt.loss,data=lung) lsa.obj=lsa(cox.obj) #find LSA estimator #LSA with AFT model library(survival) #load survival library data(lung) #load lung data lung$status=lung$status-1 #create censor indicator lung$sex=lung$sex-1 #creat gender dummy acf.obj=survreg(Surv(time,status)~age+sex+ph.ecog+ph.karno+pat.karno+meal.cal+wt.loss,data=lung,dist="weibull",scale=1) lsa.obj=lsa(acf.obj) #find LSA estimator #LSA with LAD regression library(quantreg) #load quantreg package x=matrix(rnorm(5000),500,10) #simulate the X y=x[,1]+x[,2]+x[,3]+rcauchy(500) #simulate the Y rq.obj=rq(y~x) #fit a LAD regression lsa.obj=lsa(rq.obj) #find LSA estimator