semipred: Predicted Means of a Semi Paramatric Model with Covariate...

View source: R/semipred.R

semipredR Documentation

Predicted Means of a Semi Paramatric Model with Covariate Variable(s)

Description

This function produces predicted means with graph for a semi paramatric model with new set of covariate values.

Usage

  semipred(semireg, modelterm=NULL, covariate, sm_term=NULL, contr=NULL,
           covariateV=NULL, boundary=NULL, level=0.05, trans=NULL, trellis=TRUE, 
		   scales=c("fixed", "free", "free_x", "free_y"),
		   plotord=NULL, ci=TRUE, point=TRUE, jitterv=0, threeD=FALSE, prt=TRUE)

Arguments

semireg

A list object returned by semireg.

modelterm

Name (in "quotes") for indicating which factor term's predicted mean to be calculated. The modelterm must be given exactly as it appears in semireg model, e.g. "A" or "A:B". In case modelterm is the same as covariate or NULL, them semipred will product predictmeans with CI based on covariate only with out any grouping.

covariate

Name (in "quotes") of one or two (for Ztps smooth) the covariate variables in the semireg shuch as "x1" or c("x1", "x2").

sm_term

Names (in "quotes") of smooth terms (from smoothZ list in semireg model) used in the prediction such as "sm1_grp" or c("sm1_grp", "sm2_grp"). The default is using all smooth terms which is sm_term=NULL.

contr

A numeric vector with length of two (e.g. c(4, 1)) which indicates to produce predicted mean with CI for difference between modelterm level 4 vs level 1 along covariate.

covariateV

A numeric vector or matrix, then semipred will produce the result for covariate at value of covariateV.

boundary

A matrix or data frame of two columns, used to specify boundary of longitude and latitude, it is functional when the length of covariate is two.

level

A significant level for calculating confident interval. The default value is 0.05.

trans

A function object for calculating the back transformed means, e.g. trans=exp.

trellis

A logical scalar. If set to TRUE (default), a trellis plots of predicted means with CI will be drawn.

scales

Should scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y") in a trellis graph?

plotord

A numeric vector specifying the order of plotting for two way interaction (e.g. plotord = c(2, 1) will put the second variable in modelterm on the X axis, the first variable as the grouping variable, and the third one as the panel variable). The defaults are c(1, 2) for two way interactions.

ci

A logical scalar to indicate whether to print confidence interval. The default value is TRUE.

point

A logical scalar to indicate whether to print raw data points. The default value is TRUE.

jitterv

A degree of jitter in x and y direction in the graph. The default is zero.

threeD

A logical scalar to indicate whether to produce a 3-D plot or not. The default value is FALSE.

prt

A logical scalar to indicate whether to produce plots on the screen or not. The default value is TRUE.

Value

plt

A ggplot object.

pred_df

A data.frame with predcted data.

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

Examples

# library(predictmeans)
# data(Dialyzer, package="nlme")
# help(Dialyzer)
# str(Dialyzer)
# 
# library(ggplot2)
# ggplot(Dialyzer, aes(x=rate, y=pressure, col=QB)) +
#   geom_line() +
#   facet_wrap(vars(Subject))
# 
# fm <- semireg(pressure ~ rate*QB+(rate|Subject),
#               smoothZ=list(
#                 qb_grp=smZ(rate, by=QB, group=TRUE)
#               ),
#               data=Dialyzer)
# str(fm$data)
# summary(fm$semer)
# residplot(fm$semer)
# anova(fm$semer)
# ranova(fm$semer)
# 
# ap_out1 <- semipred(fm, "QB", "rate")
# str(ap_out1$pred_df)
# ap_out2 <- semipred(fm, "QB", "rate", contr=c(1,2))
# str(ap_out2$pred_df)
# 
# help(sleepstudy)
# str(sleepstudy)
# library(latticeExtra)
# x11()
# xyplot(Reaction ~ Days | Subject, sleepstudy, aspect = "xy",
#        layout = c(9, 2), type = c("g", "p", "r"),
#        index.cond = function(x, y) coef(lm(y ~ x))[2],
#        xlab = "Days of sleep deprivation",
#        ylab = "Average reaction time (ms)",
#        as.table = TRUE)
# 
# sleep.semi <- semireg(Reaction ~ Days*Subject, 
#                     smoothZ=list(
#                       sub_grp=smZ(Days, by=Subject, group=TRUE)
#                     ), 
#                     data=sleepstudy)
# residplot(sleep.semi$semer)
# summary(sleep.semi$semer)
# anova(sleep.semi$semer)
# ranova(sleep.semi$semer)

# x11()
# predout1 <- semipred(sleep.semi, "Subject", "Days")
# str(predout1$pred_df)
# x11()
# predout2 <- semipred(sleep.semi, "Subject", "Days", contr = c(6,1))
# str(predout2$pred_df) 

predictmeans documentation built on Oct. 20, 2023, 5:07 p.m.