#########################################################################################
############## Texture of Snacks Data - a log-Student-t semiparametric model ############
#########################################################################################
data(Snacks)
Snacks2 <- Snacks[order(Snacks$snack,Snacks$week,Snacks$texture),]
attach(Snacks2)
snack <- factor(snack)
fit <- ssym.l(log(texture), formula.mu=~snack, ncs.mu=week, formula.phi=~snack,
family='Student', xi=14, local.influence=TRUE)
summary(fit)
####################### Plot of the fitted model ##############################
par(mfrow=c(1,2))
xl <- "Week"
rx <- range(week)
ry <- range(texture)
h <- fit$coefs.mu[5:length(fit$coefs.mu)]
sa <- ncs.graph(week,h,1000)
plot(week,texture,xlim=rx,ylim=ry,type="p",cex=0.3,lwd=3,ylab="",xlab="")
par(new=TRUE)
plot(sa[,1],exp(sa[,2]),xlim=rx,ylim=ry,type="l",ylab="",xlab=xl,lty=1,main="")
for(i in 2:5){
par(new=TRUE)
plot(sa[,1],exp(sa[,2] + fit$coefs.mu[i-1]),xlim=rx,ylim=ry,type="l",
ylab="",xlab="",lty=i,main="Median")
}
legend(rx[1],ry[2],lty=1:5,bty="n",legend=paste("snack",1:5))
r <- (log(texture) - fit$mu.fitted)^2/fit$xix
ry <- range(r)
plot(week,r,xlim=rx,ylim=ry,type="p",cex=0.3,lwd=3,ylab="",xlab=xl,main="Skewness")
for(i in 1:5){
abline(h=mean(fit$phi.fitted[snack==i]), lty=i)
}
legend(rx[1],ry[2],lty=1:5,bty="n",legend=paste("snack",1:5))
########################### Residual analysis ##################################
par(mfrow=c(1,2))
m1 <- "Residuals for the median submodel"
res.dev.mu <- sqrt(fit$deviance.mu)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.mu,-3.5),max(res.dev.mu,3.5))
plot(week,res.dev.mu,cex=0.3,lwd=3,ylim=ry,main=m1,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
m2 <- "Residuals for the skewness submodel"
res.dev.phi <- sqrt(fit$deviance.phi)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.phi,-3.5),max(res.dev.phi,3.5))
plot(week,res.dev.phi,cex=0.3,lwd=3,ylim=ry,main=m2,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
########################### Sensitivity analysis ##################################
par(mfrow=c(1,2))
m1 <- "Local Influence under case-weight perturbation scheme"
m2 <- "Total Local Influence under case-weight perturbation scheme"
plot(fit$cw[,1], type="h", main=m1, xlab="Index", ylab="")
plot(fit$cw[,2], type="h", main=m2, xlab="Index", ylab="")
###################################################################################
########### Fraction of Cell Volume Data - a Power-exponential model ###########
###################################################################################
data(Ovocytes)
attach(Ovocytes)
type <- factor(type)
fit <- ssym.l(fraction, formula.mu=~type, ncs.mu=time, formula.phi=~type,
family="Powerexp", xi=-0.22, local.influence=TRUE)
summary(fit)
####################### Plot of the fitted model ##############################
par(mfrow=c(1,2))
xl <- "Time"
rx <- range(time)
ry <- range(fraction)
h <- fit$coefs.mu[2:length(fit$coefs.mu)]
sa <- ncs.graph(time,h,1000)
plot(time[type=='Mature'],fraction[type=='Mature'],xlim=rx,ylim=ry,type="p",
cex=0.5,lwd=1,ylab="",xlab="")
par(new=TRUE)
plot(time[type=='Immature'],fraction[type=='Immature'],xlim=rx,ylim=ry,
type="p",cex=0.5,lwd=2,ylab="",xlab="")
par(new=TRUE)
plot(sa[,1],(sa[,2]),xlim=rx,ylim=ry,type="l",ylab="",xlab=xl,lty=1,main="")
par(new=TRUE)
plot(sa[,1],(sa[,2] + fit$coefs.mu[1]),xlim=rx,ylim=ry,type="l",ylab="",xlab=xl,
lty=1,main="Mean")
legend(rx[1],ry[2],pt.lwd=c(1,2),bty="n",legend=c("Mature","Immature"),
pt.cex=0.5,pch=1)
r <- (fraction - fit$mu.fitted)^2/fit$xix
ry <- range(r)
plot(time[type=='Mature'],r[type=='Mature'],xlim=rx,ylim=ry,type="p",cex=0.5,
lwd=1,ylab="",xlab="")
par(new=TRUE)
plot(time[type=='Immature'],r[type=='Immature'],xlim=rx,ylim=ry,type="p",
cex=0.5,lwd=2,ylab="",xlab="",main="Dispersion")
abline(h=exp(fit$coefs.phi[1]))
abline(h=exp(fit$coefs.phi[1] + fit$coefs.phi[2]))
legend(rx[1],ry[2],pt.lwd=c(1,2),bty="n",legend=c("Mature","Immature"),
pt.cex=0.5,pch=1)
########################### Residual analysis ##################################
par(mfrow=c(1,2))
m1 <- "Residuals for the mean submodel"
res.dev.mu <- sqrt(fit$deviance.mu)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.mu,-3.5),max(res.dev.mu,3.5))
plot(time,res.dev.mu,cex=0.3,lwd=3,ylim=ry,main=m1,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
m2 <- "Residuals for the dispersion submodel"
res.dev.phi <- sqrt(fit$deviance.phi)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.phi,-3.5),max(res.dev.phi,3.5))
plot(time,res.dev.phi,cex=0.3,lwd=3,ylim=ry,main=m2,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
########################### Sensitivity analysis ##################################
par(mfrow=c(1,2))
m1 <- "Local Influence under case-weight perturbation scheme"
m2 <- "Total Local Influence under case-weight perturbation scheme"
plot(fit$cw[,1], type="h", main=m1, xlab="Index", ylab="")
plot(fit$cw[,2], type="h", main=m2, xlab="Index", ylab="")
#########################################################################################
################## Biaxial Fatigue Data - a Birnbaum-Saunders model ##################
#########################################################################################
data(Biaxial)
Biaxial2 <- Biaxial[order(Biaxial$Work,Biaxial$Life),]
attach(Biaxial2)
fit <- ssym.l(log(Life), formula.mu=~log(Work), family='Sinh-normal', xi=1.54,
local.influence=TRUE)
summary(fit)
####################### Plot of the fitted model ##############################
xl <- "Work per cycle"
rx <-range(Work)
ry <- range(Life)
plot(Work,Life,xlim=rx,ylim=ry,type="p",cex=0.3,lwd=3,ylab="",xlab="")
par(new=TRUE)
plot(Work,exp(fit$mu.fitted),xlim=rx,ylim=ry,type="l",ylab="Life",xlab=xl,main="Median")
########################### Residual analysis ##################################
res.dev.mu <- sqrt(fit$deviance.mu)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.mu,-3.5),max(res.dev.mu,3.5))
plot(Work,res.dev.mu,cex=0.3,lwd=3,ylim=ry,main="Residuals",xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
########################### Sensitivity analysis ##################################
par(mfrow=c(1,2))
m1 <- "Local Influence under case-weight perturbation scheme"
m2 <- "Total Local Influence under case-weight perturbation scheme"
plot(fit$cw[,1], type="h", main=m1, xlab="Index", ylab="")
plot(fit$cw[,2], type="h", main=m2, xlab="Index", ylab="")
###################################################################################
############## Personal Claims Data - a Birnbaum-Saunders-t model ################
###################################################################################
data(Claims)
Claims2 <- Claims[order(Claims$op_time,Claims$total),]
attach(Claims2)
fit <- ssym.l(log(total), formula.mu=~op_time, formula.phi=~op_time, family='Sinh-t',
xi=c(0.1,4), local.influence=TRUE)
summary(fit)
####################### Plot of the fitted model ##############################
yl <- "Amount of paid money"
xl <- "Operational time"
rx <- range(op_time)
ry <- range(total)
par(mfrow=c(1,2))
plot(op_time,total,xlim=rx,ylim=ry,type="p",cex=0.3,lwd=3,ylab="",xlab="")
par(new=TRUE)
plot(op_time,exp(fit$mu.fitted),xlim=rx,ylim=ry,type="l",ylab=yl,xlab=xl,
main="Median")
r <- (log(total) - fit$mu.fitted)^2/fit$xix
ry <- range(r)
plot(op_time,r,xlim=rx,ylim=ry,type="p",cex=0.3,lwd=3,ylab="",xlab="")
par(new=TRUE)
plot(op_time,fit$phi.fitted,xlim=rx,ylim=ry,type="l",ylab="",xlab=xl,
main="Skewness")
########################### Residual analysis ##################################
par(mfrow=c(1,2))
m1 <- "Residuals for the median submodel"
res.dev.mu <- sqrt(fit$deviance.mu)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.mu,-3.5),max(res.dev.mu,3.5))
plot(op_time,res.dev.mu,cex=0.3,lwd=3,ylim=ry,main=m1,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
m2 <- "Residuals for the skewness submodel"
res.dev.phi <- sqrt(fit$deviance.phi)*ifelse(fit$z.hat>=0,1,-1)
ry <- c(min(res.dev.phi,-3.5),max(res.dev.phi,3.5))
plot(op_time,res.dev.phi,cex=0.3,lwd=3,ylim=ry,main=m2,xlab=xl,ylab="")
abline(h=-3,lty=3)
abline(h=+3,lty=3)
########################### Sensitivity analysis ##################################
par(mfrow=c(1,2))
m1 <- "Local Influence under case-weight perturbation scheme"
m2 <- "Total Local Influence under case-weight perturbation scheme"
plot(fit$cw[,1], type="h", main=m1, xlab="Index", ylab="")
plot(fit$cw[,2], type="h", main=m2, xlab="Index", ylab="")
Run the code above in your browser using DataLab