-
Notifications
You must be signed in to change notification settings - Fork 50
/
build.R
146 lines (100 loc) · 2.88 KB
/
build.R
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#-----BUILD SCRIPT--------------------------------------------------------------
#-----Generate documentation----------------------------------------------------
roxygen2::roxygenise()
#-----Create website for package------------------------------------------------
pkgdown::build_site()
#-----Build package-------------------------------------------------------------
# piecewiseSEM <- devtools::as.package("./piecewiseSEM")
# Add files to .Rbuildignore
usethis::use_build_ignore(c("build.R", ".git", ".gitignore", "docs"))
# Load package
devtools::load_all(".", reset = T)
# Check and build
devtools::check(".", cran = T)
devtools::build(".")
devtools::check_built(".")
# Check on R-hub
# devtools::spell_check()
# devtools::check_rhub("piecewiseSEM")
# check_win_devel()
#-----Examples------------------------------------------------------------------
#run_examples(piecewiseSEM)
library(piecewiseSEM)
data(keeley)
# fit model
mod <- psem(
lm(rich ~ cover, data=keeley),
lm(cover ~ firesev, data=keeley),
lm(firesev ~ age, data=keeley),
data = keeley)
mod
# d-sep tests
basisSet(mod)
dSep(mod)
fisherC(mod)
AIC(mod) #likelihood based
AIC(mod, AIC.type = "dsep") #dsep based
# Chisq
LLchisq(mod)
AIC(mod, AIC.type = "loglik")
# Rsquared
rsquared(mod)
# get summary
summary(mod)
# get residuals
residuals(mod)
# plotting
# plot(mod)
#
# plot(mod, node_attrs = list(
# shape = "rectangle", color = "black",
# fillcolor = "orange", x = 3, y = 1:4))
# add correlated error
mod2 <- psem(
lm(rich ~ cover, data=keeley),
lm(cover ~ firesev + age, data=keeley),
lm(firesev ~ age, data=keeley),
rich %~~% firesev,
data = keeley)
# get summary
summary(mod2)
# AIC of two models
anova(mod, mod2)
# test mixed models
library(lme4)
# library(MASS)
library(nlme)
# using lme
shipley_psem <- psem(
lme(DD ~ lat, random = ~ 1 | site / tree, na.action = na.omit,
data = shipley),
lme(Date ~ DD, random = ~ 1 | site / tree, na.action = na.omit,
data = shipley),
lme(Growth ~ Date, random = ~ 1 | site / tree, na.action = na.omit,
data = shipley),
glmer(Live ~ Growth + (1 | site) + (1 | tree),
family = binomial(link = "logit"), data = shipley))
summary(shipley_psem)
# using lme4
shipley_psem_lme4 <- psem(
lmer(DD ~ lat + (1 | site / tree),
data = shipley),
lmer(Date ~ DD + (1 | site / tree),
data = shipley),
lmer(Growth ~ Date + (1 | site / tree),
data = shipley),
glmer(Live ~ Growth + (1 | site) + (1 | tree),
family = binomial(link = "logit"), data = shipley),
data = shipley)
summary(shipley_psem_lme4)
# multigroup
data(meadows)
meadows$grazed <- factor(meadows$grazed)
meadow_mod <- psem(
lm(mass ~ elev, data = meadows),
lm(rich ~ elev + mass, data = meadows),
data = meadows
)
multigroup(meadow_mod, group = "grazed")
#-----Submit to CRAN------------------------------------------------------------
devtools::release(".")