if (FALSE) {
###########################
# Probit Regression Model #
###########################
# Simulate data
set.seed(1)
f <- function(x) 1.5 * sin(pi * x)
n <- 1000
b <- c(1,-1)
rho <- 0.7
u <- runif(n, min = -1, max = 1)
x <- runif(n, min = -1, max = 1)
w1 <- runif(n, min = -1, max = 1)
w2 <- round(f(rho * x + (1 - rho) * u))
w <- cbind(w1, w2)
y <- w %*% b + f(x) + rnorm(n)
y <- (y > 0)
# Number of cosine basis functions
nbasis <- 50
# Fit the model with default priors and mcmc parameters
fout <- gbsar(y ~ w1 + w2 + fs(x), family = "bernoulli", link = "probit",
nbasis = nbasis, shape = 'Free')
# Summary
print(fout); summary(fout)
# fitted values
fit <- fitted(fout)
# Plot
plot(fit, ask = TRUE)
######################################
# Logistic Additive Regression Model #
######################################
# Wage-Union data
data(wage.union); attach(wage.union)
race[race==1 | race==2]=0
race[race==3]=1
y <- union
w <- cbind(race,sex,south)
x <- cbind(wage,education,age)
# mcmc parameters
mcmc <- list(nblow0 = 10000,
nblow = 10000,
nskip = 10,
smcmc = 1000,
ndisp = 1000,
maxmodmet = 10)
foutGBSAR <- gbsar(y ~ race + sex + south + fs(wage) + fs(education) + fs(age),
family = 'bernoulli', link = 'logit', nbasis = 50, mcmc = mcmc,
shape = c('Free','Decreasing','Increasing'))
# fitted values
fitGBSAR <- fitted(foutGBSAR)
# Plot
plot(fitGBSAR, ask = TRUE)
}
# \dontshow{
# Toy Example : Probit Regression Model #
# Simulate data
set.seed(1)
f <- function(x) 1.5 * sin(pi * x)
n <- 100
b <- c(1,-1)
rho <- 0.7
u <- runif(n, min = -1, max = 1)
x <- runif(n, min = -1, max = 1)
w1 <- runif(n, min = -1, max = 1)
w2 <- round(f(rho * x + (1 - rho) * u))
w <- cbind(w1, w2)
y <- w %*% b + f(x) + rnorm(n)
y <- (y > 0)
# Number of cosine basis functions
nbasis <- 10
# Fit the model with default priors and mcmc parameters
fout <- gbsar(y ~ w1 + w2 + fs(x), family = "bernoulli", link = "probit",
nbasis = nbasis, shape = 'Free')
# Summary
print(fout); summary(fout)
# fitted values
fit <- fitted(fout)
# Plot
plot(fit, ask = FALSE)
# }
Run the code above in your browser using DataLab