# predict.GPCMlasso: Predict function for GPCMlasso In GPCMlasso: Differential Item Functioning in Generalized Partial Credit Models

 predict.GPCMlasso R Documentation

## Predict function for GPCMlasso

### Description

Predict function for a `GPCMlasso` object. Predictions can be linear predictors or probabilities separately for each person and each item.

### Usage

```## S3 method for class 'GPCMlasso'
predict(
object,
coefs = NULL,
newdata = NULL,
type = c("link", "response"),
...
)
```

### Arguments

 `object` `GPCMlasso` object `coefs` Optional vector of coefficients, can be filled with a specific row from `object\$coefficients`. If not specified, `coefs` are specififed to be the BIC-optimal coefficients or, if cross-validation was performed, the optimal coefficients according to cross-validation. `newdata` List possibly containing slots Y, X, Z1 and Z2 to use new data for prediction. `type` Type "link" gives vectors of linear predictors for separate categories (of length \$k_i-1\$) and type "response" gives the respective probabilities (of length \$k_i\$). `...` Further predict arguments.

### Details

Results are lists of vectors with length equal to the number of response categories \$k_i\$ in case of probabilities (`type="response"`) or \$k_i-1\$ in case of linear predictors (`type="link"`).

### Author(s)

Gunther Schauberger
gunther@stat.uni-muenchen.de

`GPCMlasso`

### Examples

```data(tenseness_small)

## formula for simple model without covariates
form.0 <- as.formula(paste("cbind(",paste(colnames(tenseness_small)[1:5],collapse=","),")~0"))

######
## fit simple RSM where loglikelihood and score function are evaluated parallel on 2 cores
rsm.0 <- GPCMlasso(form.0, tenseness_small, model = "RSM",
control= ctrl_GPCMlasso(cores=2))
rsm.0

## Not run:
## formula for model with covariates (and DIF detection)
form <- as.formula(paste("cbind(",paste(colnames(tenseness_small)[1:5],collapse=","),")~."))

######
## fit GPCM model with 10 different tuning parameters
gpcm <- GPCMlasso(form, tenseness_small, model = "GPCM",
control = ctrl_GPCMlasso(l.lambda = 10))
gpcm
plot(gpcm)
pred.gpcm <- predict(gpcm)
trait.gpcm <- trait.posterior(gpcm)

######
## fit RSM, detect differential step functioning (DSF)
rsm.DSF <- GPCMlasso(form, tenseness_small, model = "RSM", DSF = TRUE,
control = ctrl_GPCMlasso(l.lambda = 10))
rsm.DSF
plot(rsm.DSF)

## create binary data set
tenseness_small_binary <- tenseness_small
tenseness_small_binary[,1:5][tenseness_small[,1:5]>1] <- 2

######
## fit and cross-validate Rasch model
set.seed(1860)
rm.cv <- GPCMlasso(form, tenseness_small_binary, model = "RM", cv = TRUE,
control = ctrl_GPCMlasso(l.lambda = 10))
rm.cv
plot(rm.cv)

## End(Not run)
```

GPCMlasso documentation built on May 3, 2022, 5:05 p.m.