sqlmodelmatrix {surveyNG}R Documentation

Create model matrix in a SQL table

Description

Given a formula and a sqlsurvey design object, create SQL tables with a model frame and model matrix.

Usage

sqlmodelmatrix(formula, design, fullrank = TRUE)

Arguments

formula model formula
design sqlsurvey object
fullrank if FALSE return a matrix of indicators for any factor variables, not a full-rank design matrix

Details

Currently, no transformations are allowed in the formula, factors will be coded with treatment contrasts, and interactions are allowed only between factor variables.

The database tables created by this function will be removed if the R object is deleted and garbage collected.

Value

An object of class sqlmodelmatrix

See Also

link{open.sqlmodelmatrix} for reconnecting saved objects

Examples

sqclus1<-sqlsurvey(id="dnum", fpc="fpc", weights="pw", strata="fpc",
   data=system.file("apiclus1.db",package="surveyNG"),
   table.name="clus1", key="snum")
mm <- sqlmodelmatrix(api00~stype*comp_imp+ell+api99, sqclus1)
dbGetQuery(sqclus1$conn,
     sqlsubst("select * from %%mm%% limit 2", list(mm=mm$table)))
dbListTables(sqclus1$conn)
rm(mm)
gc()
dbListTables(sqclus1$conn)
close(sqclus1)

[Package surveyNG version 0.3 Index]