R: Function to plot predicted risks against risk scores

plotRiskscorePredrisk {PredictABEL}R Documentation

Function to plot predicted risks against risk scores.


This function is used to make a plot of predicted risks against risk scores.


plotRiskscorePredrisk(data, riskScore, predRisk, plottitle, xlabel, 
ylabel, rangexaxis, rangeyaxis, filename, fileplot, plottype)



Data frame or matrix that includes the outcome and predictors variables.


Vector of (weighted or unweighted) genetic risk scores.


Vector of predicted risks.


Title of the plot. Specification of plottitle is optional. Default is "Risk score predicted risk plot".


Label of x-axis. Specification of xlabel is optional. Default is "Risk score".


Label of y-axis. Specification of ylabel is optional. Default is "Predicted risk".


Range of the x axis. Specification of rangexaxis is optional.


Range of the y axis. Specification of rangeyaxis is optional. Default is c(0,1).


Name of the output file in which risk scores and predicted risks for each individual will be saved. If no directory is specified, the file is saved in the working directory as a txt file. When no filename is specified, the output is not saved.


Name of the output file that contains the plot. The file is saved in the working directory in the format specified under plottype. Example: fileplot="plotname". Note that the extension is not specified here. When fileplot is not specified, the plot is not saved.


The format in which the plot is saved. Available formats are wmf, emf, png, jpg, jpeg, bmp, tif, tiff, ps, eps or pdf. For example, plottype="eps" will save the plot in eps format. When plottype is not specified, the plot will be saved in jpg format.


The function creates a plot of predicted risks against risk scores. Predicted risks can be obtained using the functions fitLogRegModel and predRisk or be imported from other methods or packages. The function riskScore can be used to compute unweighted or weighted risk scores.


The function creates a plot of predicted risks against risk scores.

See Also

riskScore, predRisk


# specify dataset with outcome and predictor variables

# fit a logistic regression  model
# all steps needed to construct a logistic regression model are written in a function
# called 'ExampleModels', which is described on page 4-5
riskmodel <- ExampleModels()$riskModel2

# obtain predicted risks
predRisk <- predRisk(riskmodel)

# specify column numbers of genetic predictors
cGenPred <- c(11:16)

# function to compute unweighted genetic risk scores
riskScore <- riskScore(weights=riskmodel, data=ExampleData, 
cGenPreds=cGenPred, Type="unweighted")

# specify range of x-axis
rangexaxis <- c(0,12)   
# specify range of y-axis
rangeyaxis <- c(0,1)     
# specify label of x-axis
xlabel <- "Risk score"     
# specify label of y-axis
ylabel <- "Predicted risk" 
# specify title for the plot
plottitle <- "Risk score versus predicted risk"

# produce risk score-predicted risk plot
plotRiskscorePredrisk(data=ExampleData, riskScore=riskScore, predRisk=predRisk, 
plottitle=plottitle, xlabel=xlabel, ylabel=ylabel, rangexaxis=rangexaxis, 
rangeyaxis=rangeyaxis, filename="RiskscorePredRisk.txt")