sem: Interfaces for sem package for data science pipelines.

Description Usage Arguments Details Value Author(s) Examples

Description

Interfaces to sem functions that can be used in a pipeline implemented by magrittr.

Usage

1
2
3

Arguments

data

data frame, tibble, list, ...

...

Other arguments passed to the corresponding interfaced function.

Details

Interfaces call their corresponding interfaced function.

Value

Object returned by interfaced function.

Author(s)

Roberto Bertolusso

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
## Not run: 
library(intubate)
library(magrittr)
library(sem)


## ntbt_rawMoments: Compute Raw Moments Matrix
## Original function to interface
rawMoments(~ Q + P + D + F + A, data = Kmenta)

## The interface puts data as first parameter
ntbt_rawMoments(Kmenta, ~ Q + P + D + F + A)

## so it can be used easily in a pipeline.
Kmenta %>%
  ntbt_rawMoments(~ Q + P + D + F + A)


## ntbt_sem: General Structural Equation Models
## NOTE: this example is NOT using the formula interface.
##       It is creating a list with the variables.
R.DHP <- readMoments(diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp", 
                "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp"),
                text="
    .6247     
    .3269  .3669       
    .4216  .3275  .6404
    .2137  .2742  .1124  .0839
    .4105  .4043  .2903  .2598  .1839
    .3240  .4047  .3054  .2786  .0489  .2220
    .2930  .2407  .4105  .3607  .0186  .1861  .2707
    .2995  .2863  .5191  .5007  .0782  .3355  .2302  .2950
    .0760  .0702  .2784  .1988  .1147  .1021  .0931 -.0438  .2087
")

model.dhp.1 <- specifyEquations(covs="RGenAsp, FGenAsp", text="
RGenAsp = gam11*RParAsp + gam12*RIQ + gam13*RSES + gam14*FSES + beta12*FGenAsp
FGenAsp = gam23*RSES + gam24*FSES + gam25*FIQ + gam26*FParAsp + beta21*RGenAsp
ROccAsp = 1*RGenAsp
REdAsp = lam21(1)*RGenAsp  # to illustrate setting start values
FOccAsp = 1*FGenAsp
FEdAsp = lam42(1)*FGenAsp
")

dta <- list(R.DHP = R.DHP, model.dhp.1 = model.dhp.1)
rm(R.DHP, model.dhp.1)

## Original function to interface
attach(dta)
sem.dhp.1 <- ntbt_sem(model.dhp.1, R.DHP, 329,
                      fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
summary(sem.dhp.1)
detach()

## The interface puts data as first parameter
sem.dhp.1 <- ntbt_sem(dta, model.dhp.1, R.DHP, 329,
                      fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
summary(sem.dhp.1)

## so it can be used easily in a pipeline.
dta %>%
  ntbt_sem(model.dhp.1, R.DHP, 329,
           fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp')) %>%
  summary()


## ntbt_tsls: Two-Stage Least Squares
## Original function to interface
tsls(Q ~ P + D, ~ D + F + A, data = Kmenta)

## The interface puts data as first parameter
ntbt_tsls(Kmenta, Q ~ P + D, ~ D + F + A)

## so it can be used easily in a pipeline.
Kmenta %>%
  ntbt_tsls(Q ~ P + D, ~ D + F + A)

## End(Not run)

rbertolusso/intubate documentation built on May 27, 2019, 3 a.m.