Variable Types PASS
Reviewing
the data, I saw that the predictor variables are quantitative (interval)
and the outcome variable is quantitative, continuous, and unbounded.
Thus, I concluded that this assumption was not violated.
Non-zero Variance PASS
Examining the variance for each predictor variable, I saw that neither
Ability_Tot (\(var\) = 74303.55) nor
Motivate_Tot (\(var\) = 86.53804) had 0
variance and concluded that this assumption was not violated.
No perfect Multicollinearity PASS
Reviewing a correlation matrix of
the predictor variables, I concluded that there was no strong evidence
of multicollinearity between the composite variables (\(r\) = .04, \(p\) = .26). I calculated the Variance
Inflation Factor (VIF) and the resulting values were below 5 which is
considered acceptable and suggests that there are no significant
multicollinearity issues in the model.
Homoscedasticity PASS
I
conducted a Non-constant Variance Score test (ncvTest) and based on the
results I failed to reject the null hypothesis (\(p\) = .81), concluding that the assumption
of Homoscedasticity was not violated.
Independent Errors (Durbin-Watson test) PASS
Based on the Durbin-Watson test
results (\(DW\) = 2.10, \(p\) = .94), I concluded that the errors in
my regression model were independent and that the assumption of
independent errors was not violated.
Normally Distributed Errors PASS
I conducted a Shapiro-Wilk
normality test and based on the results I failed to reject the null
(\(W\) = .998, \(p\) = .47), concluding that the assumption
of normality had not been violated. To visually assess, I examined
quantile-quantile (Q-Q) plots for the residuals of my model to see how
well the residuals conformed to a normal distribution. Both plots were
relatively normally distributed with only minor deviations, bolstering
the conclusion that the assumption of normailty had not been
violated.
Independence PASS
I visually
assessed a scatterplot of residuals against fitted values and found no
discernible pattern. Thus, I concluded that the assumption of
independence was not violated.
Linearity PASS
To assess for
linearity, I visually assessed a scatterplot and finding it relatively
linear, concluded that the assumption of linearity had not been
violated.
Outliers and Influential Cases CAUTION
To assess outliers and
influential cases, I calculated the standardized residuals (z-scores)
for the model to identify potential outliers. I then sorted and analyzed
residual magnitudes, finding 3 cases above a z-score of 3, 9 cases above
2.58 (indicating a 1% level of extremeness), and 49 cases above 1.96
(indicating a 5% level of extremeness). These findings suggested that my
model may have notable outliers, potentially impacting its predictive
accuracy.
Overall the data appears to meet all assumptions and potential
outliers do not appear to be acting as influential cases. That said, I
would still consider bootstrapping my regression analyses to remove the
issue of having to meet assumptions in the first place.
Overall, the model accounted for a significant proportion of the
variance in GPA, \(R^2\) = .24, \(F\)(2, 997) = 161.6, \(p\) < .001.
Independent of Motivation test scores, GPA is significantly higher
the higher an individual scores on Ability tests, \(b\) = 0.001, \(t\)(997) = 17.86, \(p\) < .001. However, independent of
Ability test scores, Motivation test scores do not signficantly impact
GPA, \(b\) = 0.002, \(t\)(997) = 1.39, \(p\) = .17.
Overall, the model accounted for a significant proportion of the
variance in GPA, \(R^2\) = .29, \(F\)(5, 994) = 82.43, \(p\) < .001. Several of the predictors
are statistically significant in predicting GPA.
Holding all other predictor variables constant, every 1 unit increase
in GREV is associated with an increase of 0.001 units in GPA, \(t\)(994) = 4.50, \(p\) < .001.
Holding all other predictor variables constant, every 1 unit increase
in GREA is associated with an increase of 0.001 units in GPA, \(t\)(994) = 6.08, \(p\) < .001.
Holding all other predictor variables constant, every 1 unit increase
in Ach is associated with an increase of 0.006 units in GPA, \(t\)(994) = 3.33, \(p\) < .001.
For an individual with average scores on all GRE and Motivation
tests, the typical GPA would be 4.00, \(t\) = 299.26, \(p\) < .001, 95% CI [3.98, 4.03]. The R
code provided below shows how to center the predictor variables on the
mean to produce a centered multiple regression. While this shifts the
distribution it does not alter which predictor variables significantly
predict change in GPA.
I conducted a simple mediation analysis using ordinary least squares
path analysis and found that vocabulary scores indirectly influenced
general reading achievement through its effect on general language
ability.
The total effect of vocabulary scores on general reading achievement
was significant (\(c\) = 0.53, \(p\) < .001), indicating a substantial
overall relationship. Further, participants with higher vocabulary
scores experienced higher general language ability (\(β_a\) = 0.71, \(p\) < .001), and participants with
higher language ability experienced greater general reading achievement
(\(β_b\) = 0.24, \(p\) < .001).
A bootstrap confidence interval for the indirect effect (\(β_{ab}\) = 0.17) based on 10,000 bootstrap
samples was entirely above zero (0.16 to 0.18). While there was evidence
that vocabulary scores had a direct effect on general reading
achievement (\(c'\) = 0.36, \(p\) < .001), these overall findings
confirm that general language ability acts as a significant mediator in
the relationship between vocabulary scores and general reading
achievement.
I conducted a PROCESS moderation analysis following the methodology
of Maxwell et al. (2017), to explore the impact of sexual destiny
beliefs (SexDestiny) on perceived relationship quality (Tot_PRQCI), with
a focus on the moderating role of sexual compatibility (SexCompat). The
overall model was statistically significant, accounting for 10.83% of
the variance in perceived relationship quality (\(F\)(4, 655) = 19.89, \(p\) < .001.), demonstrating that both
sexual destiny beliefs and sexual compatibility are cruical factors
influencing perceived relationship quality.
The influence of sexual destiny beliefs on perceived relationship quality was not significant (\(β\) = 0.30, \(p\) = .21), indicating that these beliefs by themselves do not significantly impact perceived relationship quality. Similarly, the direct effect of sexual compatibility on perceived relationship quality was not significant (\(β\) = -0.97, \(p\) = .31), suggesting that the level of sexual compatibility alone does not determine perceived relationship quality. However, a signficant interaction effect between sexual destiny beliefs and sexual compatibility (\(β\) = -0.15, \(p\) = .011) was observed. This interaction indicates that the negative impact of sexual destiny beliefs on relationship quality is exacerbated at lower levels of sexual compatibility.
Thus, the effect of sexual destiny beliefs on perceived relationship
quality is increasingly negative as sexual compatibility decreases,
highlighting the significant moderatng effect of sexual compatibility.
This finding supports the hypothesis proposed by Maxwell et al. (2017)
regarding the combined influence of sexual destiny beliefs and sexual
compatibility on perceived relationship quality.
I conducted a three-way interaction model to explore the relationship
between sexual destiny beliefs, sexual compatibility, and relationship
quality, including a moderator for sample type to investigate
generalizability across queer and representative samples. The overall
model was statistically significant, accounting for 11.68% of the
variance in perceived relationship quality (\(F\)(8, 651) = 10.76, \(p\) < .001.), demonstrating that both
sexual destiny beliefs and sexual compatibility are cruical factors
influencing perceived relationship quality in both queer and
representative samples.
While my initial finding suggested some level of generalizability
across samples, I wanted a more nuanced understanding of the differences
between groups. Thus, I conducted two PROCESS moderation analyses–the
first on the representative sample and the second on the queer sample–to
explore the impact of sexual destiny beliefs on perceived relationship
quality, with a focus on the moderating role of sexual compatibility. As
suspected, the results of the individual analyses point to differences
by group in the mechanisms underlying these relationships. Specifically,
the direct negative impact of sexual destiny beliefs on relationship
quality is more pronounced in the queer sample (\(β\) = -0.39, \(p\) = .003) than in the representative
sample (\(β\) = -0.21, \(p\) = .01), suggesting that the impact of
sexual beliefs and compatibility on relationship quality can vary
significantly across different demographic and relationship
contexts.
Thus, the results of the three-way interaction model indicated that
the findings were generalizable across samples. Yet, further analyses
provided a more nuanced understanding of the moderator’s influence
specific to each group, allowing us to honour the more subtle
differences between populations.
# Load relevant packages
library(tidyverse);library(car);library(QuantPsyc);library(boot);library(Hmisc);library(lmtest); library(readxl); #library(psych)
#### Read in data ####
datafilename="http://personality-project.org/R/datasets/psychometrics.prob2.txt"
dataset =read.table(datafilename,header=TRUE)
# Ability tests: GRE Verbal Scores (GREV), GRE Quantitative Scores (GREQ), & GRE Advanced Scores (GREA)
# Motivation tests: Need for Achievement (Ach) & Anxiety (Anx)
# Graduate School Performance measures: graduate GPA (GPA), performance on the Comprehensive Examinations (Prelim), & the quality of the Master’s Thesis (MA).
#### 1.A-B. Create Ability and Motivation composites ####
clean.dat <- dataset%>%
rowwise() %>%
mutate(
Ability_Tot = sum(c_across(starts_with("GRE")), na.rm = FALSE), #GRE score composite
Motivate_Tot = sum(Ach+Anx, na.rm = FALSE), #Motivation test score composite
)
#### 1.C. Multiple regression analysis predicting GPA from Ability and Motivation composites ####
model1 <-lm(GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat, na.action = na.exclude)
summary(model1) # Significant model: F(2,997) = 161.6, R-sq = .24, p<.001
##
## Call:
## lm(formula = GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat,
## na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.31967 -0.31147 0.01266 0.30473 1.39856
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.4395853 0.1653663 14.753 <2e-16 ***
## Ability_Tot 0.0009058 0.0000507 17.864 <2e-16 ***
## Motivate_Tot 0.0020591 0.0014857 1.386 0.166
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4366 on 997 degrees of freedom
## Multiple R-squared: 0.2448, Adjusted R-squared: 0.2433
## F-statistic: 161.6 on 2 and 997 DF, p-value: < 2.2e-16
plot(model1)
confint(model1) # CI for Ability_Tot and Motivate_Tot include 0, model CI [2.115, 2.764]
## 2.5 % 97.5 %
## (Intercept) 2.1150792603 2.764091275
## Ability_Tot 0.0008062660 0.001005263
## Motivate_Tot -0.0008564176 0.004974662
# Pearson's correlation coefficient
sqrt(0.2448) # r = .49
## [1] 0.4947727
#### Checking Assumptions ####
#### 1. Variable Types ####
# *PASS* (predictor variables are quantitative (interval) and outcome variable is quantitative, continuous, and unbounded)
#### 2. Non-Zero Variance ####
# *PASS*
summary(clean.dat$Ability_Tot)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 673 1302 1495 1498 1682 2545
summary(clean.dat$Motivate_Tot)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 72.0 94.0 100.0 100.2 107.0 127.0
var(clean.dat$Ability_Tot) # var = 74303.55
## [1] 74303.55
var(clean.dat$Motivate_Tot) # var = 86.53804
## [1] 86.53804
#### 3. Multicollinearity ####
# *PASS*
Matrix <- as.matrix(clean.dat[,c("Ability_Tot","Motivate_Tot")])
rcorr(Matrix, type = "pearson")
## Ability_Tot Motivate_Tot
## Ability_Tot 1.00 0.04
## Motivate_Tot 0.04 1.00
##
## n= 1000
##
##
## P
## Ability_Tot Motivate_Tot
## Ability_Tot 0.263
## Motivate_Tot 0.263
# above .80 or .90 is considered very highly correlated --> r = .04, p = 0.263 is ok!
# VIF values below 5 are considered acceptable, and values above 10 may indicate a problematic level of multicollinearity
vif.model1 <- vif(model1)
sqrt(vif.model1) # Ability = 1.000628; Motivation = 1.000628
## Ability_Tot Motivate_Tot
## 1.000628 1.000628
#### 4. Homoscedasticity ####
# *PASS*
ncvTest(model1)
## Non-constant Variance Score Test
## Variance formula: ~ fitted.values
## Chisquare = 0.06051397, Df = 1, p = 0.80569
# Homoscedasticity assumes that the variance of the errors is constant across all levels of the independent variables.
# The null hypothesis for the non-constant variance test is that there is homoscedasticity, meaning the variance of the residuals is constant across all levels of the independent variables.
# Fail to reject the null hypothesis, p = 0.80569
#### 5. Independent Errors (Durbin-Watson test) ####
# *PASS*
dw_test <- dwtest(model1)
print(dw_test) # DW = 2.0994, p-value = 0.9424
##
## Durbin-Watson test
##
## data: model1
## DW = 2.0994, p-value = 0.9424
## alternative hypothesis: true autocorrelation is greater than 0
# The test statistic (DW) can vary between 0 and 4, with a value of 2 meaning that the residuals are uncorrelated. A value greater than 2 indicates a negative correlation between adjacent residuals, whereas a value less than 2 indicates a positive correlation.
#### 6. Normally Distributed Errors ####
# *PASS*
shapiro.test(residuals(model1)) # W = .99837, p = .4723 --> fail to reject the null; data is normally distributed;
##
## Shapiro-Wilk normality test
##
## data: residuals(model1)
## W = 0.99837, p-value = 0.4723
plot(model1, which = 2) # Q-Q plots
qqnorm(residuals(model1)) # minor deviation at the tails; mostly normally distributed errors
qqline(residuals(model1)) # minor deviation at the tails; mostly normally distributed errors
#### 7. Independence ####
# *PASS*
# If there is no discernible structure, it suggests that the independence assumption may hold
plot(model1, which = 1) # Scatterplot of residuals against fitted values
# Outliers flagged 186, 580, 780
#### 8. Linearity ####
# *PASS*
fitted.values(object=model1)
## 1 2 3 4 5 6 7 8
## 3.772764 3.976887 3.936218 3.909124 3.997381 4.494411 4.346524 3.829175
## 9 10 11 12 13 14 15 16
## 4.397826 4.015014 4.081956 3.559583 3.940246 4.109370 4.303796 3.950457
## 17 18 19 20 21 22 23 24
## 3.856825 4.147340 4.193202 4.174513 4.027525 3.894221 4.060296 3.949714
## 25 26 27 28 29 30 31 32
## 3.910030 3.807105 3.889197 4.386456 3.718998 3.867948 4.104443 3.805867
## 33 34 35 36 37 38 39 40
## 3.795994 4.093972 4.080476 3.626531 4.074221 4.178879 4.001844 3.763217
## 41 42 43 44 45 46 47 48
## 3.792033 4.287154 3.553484 4.301561 3.583290 3.883092 3.766417 3.816560
## 49 50 51 52 53 54 55 56
## 3.910277 3.392844 3.554305 3.788331 4.367096 3.864077 3.887965 4.039632
## 57 58 59 60 61 62 63 64
## 4.455222 3.518322 3.982249 4.225320 4.307993 3.993680 4.546528 4.013281
## 65 66 67 68 69 70 71 72
## 4.173184 4.474152 3.996234 3.993855 3.956387 3.729619 3.851885 4.068701
## 73 74 75 76 77 78 79 80
## 3.816156 3.617546 4.048781 4.158131 4.248369 4.480909 4.019712 4.111279
## 81 82 83 84 85 86 87 88
## 3.995823 4.262294 4.047126 4.241618 3.739335 3.813686 4.508088 4.025726
## 89 90 91 92 93 94 95 96
## 3.424214 4.295638 4.154169 3.679386 4.037978 4.048853 3.874711 3.740482
## 97 98 99 100 101 102 103 104
## 3.878485 3.573978 4.168010 4.047283 4.364313 3.816977 3.799025 4.109539
## 105 106 107 108 109 110 111 112
## 3.942057 4.440313 3.688039 3.888128 3.860128 4.325196 4.473500 4.237343
## 113 114 115 116 117 118 119 120
## 3.897753 3.870091 3.976229 3.905169 4.164224 3.803397 4.442281 3.746158
## 121 122 123 124 125 126 127 128
## 3.938428 4.070350 4.160842 3.934570 4.068864 4.049107 4.143391 4.657279
## 129 130 131 132 133 134 135 136
## 3.533727 4.298603 4.277118 3.986446 4.209004 4.293657 4.102384 4.052802
## 137 138 139 140 141 142 143 144
## 4.162653 3.826276 4.238158 4.280910 4.339936 4.187272 3.709680 4.372797
## 145 146 147 148 149 150 151 152
## 3.763785 4.221202 4.207362 3.941641 4.092668 4.393207 4.113416 3.540308
## 153 154 155 156 157 158 159 160
## 4.152527 3.669742 3.581811 4.049765 4.113579 4.164875 3.767903 3.936949
## 161 162 163 164 165 166 167 168
## 3.707543 4.094395 4.215846 4.232711 3.698400 4.269280 4.293494 3.949557
## 169 170 171 172 173 174 175 176
## 4.317292 3.774980 4.216673 3.540061 3.564692 4.108881 3.865315 4.109219
## 177 178 179 180 181 182 183 184
## 3.884505 4.142238 3.755222 4.237669 4.050755 4.548262 4.483626 3.968898
## 185 186 187 188 189 190 191 192
## 3.707712 3.844482 4.172708 3.885978 3.974587 3.711341 4.446738 3.835835
## 193 194 195 196 197 198 199 200
## 3.842514 4.581195 4.021276 4.150455 3.498305 3.849428 4.751485 3.554142
## 201 202 203 204 205 206 207 208
## 4.056503 3.886467 4.270198 3.504905 3.758018 4.459008 3.828269 3.929051
## 209 210 211 212 213 214 215 216
## 4.120565 4.063025 4.061872 3.694210 4.311290 3.914305 4.268634 4.436025
## 217 218 219 220 221 222 223 224
## 4.129635 3.872404 4.090440 4.125928 3.763869 4.255537 4.183655 3.817642
## 225 226 227 228 229 230 231 232
## 4.107486 4.051902 4.020611 4.129720 4.196577 3.975317 4.428942 3.839308
## 233 234 235 236 237 238 239 240
## 3.973518 3.987346 4.363642 4.208769 3.606840 3.979025 3.648746 3.703594
## 241 242 243 244 245 246 247 248
## 3.835014 3.850165 4.288301 4.204397 4.170727 4.034856 3.514706 3.876190
## 249 250 251 252 253 254 255 256
## 3.897421 4.412481 4.192459 3.702121 3.791199 4.186282 3.719734 4.125348
## 257 258 259 260 261 262 263 264
## 4.013613 4.346530 4.198057 3.874457 3.880139 3.779013 3.911105 4.131447
## 265 266 267 268 269 270 271 272
## 3.952190 3.961248 3.866716 4.048110 3.807763 3.955324 3.867054 3.888949
## 273 274 275 276 277 278 279 280
## 4.196577 3.933899 4.246238 4.055037 4.045067 3.501113 3.915627 4.237349
## 281 282 283 284 285 286 287 288
## 3.807757 4.132854 3.669181 4.201360 3.949394 4.016584 4.161748 3.953911
## 289 290 291 292 293 294 295 296
## 3.812781 4.117190 4.191469 4.275137 3.800269 4.950669 4.304695 3.933169
## 297 298 299 300 301 302 303 304
## 4.179120 4.349404 4.031891 4.186946 3.729607 3.689518 4.095555 3.767166
## 305 306 307 308 309 310 311 312
## 3.759099 3.849422 3.794255 4.193196 4.393545 3.865490 4.053225 3.878817
## 313 314 315 316 317 318 319 320
## 4.355001 4.087318 3.791948 4.304460 3.901956 3.921557 3.952353 4.219384
## 321 322 323 324 325 326 327 328
## 4.589770 4.001596 4.175256 3.669579 3.629810 3.972117 4.163390 3.510750
## 329 330 331 332 333 334 335 336
## 3.777939 4.453977 3.897108 4.038068 3.999108 3.675515 3.769714 3.787993
## 337 338 339 340 341 342 343 344
## 4.439002 3.857404 3.755138 4.442124 3.917686 3.894215 4.471435 3.641506
## 345 346 347 348 349 350 351 352
## 3.871076 3.610228 3.794756 3.766743 3.541866 3.734233 3.869433 3.984218
## 353 354 355 356 357 358 359 360
## 4.035104 4.612825 3.953839 3.551015 4.108966 3.975740 4.011807 4.142153
## 361 362 363 364 365 366 367 368
## 4.383660 3.994839 3.818052 3.747318 3.695605 3.880719 4.132835 4.000196
## 369 370 371 372 373 374 375 376
## 3.238604 4.221534 4.244830 3.776635 4.021523 4.013196 3.985860 4.009990
## 377 378 379 380 381 382 383 384
## 3.363521 4.057422 3.625535 3.965118 4.091170 4.074051 4.134816 3.952021
## 385 386 387 388 389 390 391 392
## 4.914112 3.701046 4.125276 3.895374 3.793108 3.742705 3.891830 3.975740
## 393 394 395 396 397 398 399 400
## 4.136809 4.006125 3.493202 4.232808 3.861535 3.459037 3.518661 3.896528
## 401 402 403 404 405 406 407 408
## 3.932009 4.058575 4.195183 3.914051 4.098839 4.463941 4.380200 4.029421
## 409 410 411 412 413 414 415 416
## 4.113996 3.976307 4.565393 3.928556 4.352623 3.750784 4.007025 3.738762
## 417 418 419 420 421 422 423 424
## 3.860629 3.924359 3.726238 4.039965 3.951864 3.710526 4.160268 4.164139
## 425 426 427 428 429 430 431 432
## 3.924848 3.640848 4.094063 4.089534 3.955312 4.192381 3.891165 4.022338
## 433 434 435 436 437 438 439 440
## 4.521831 3.797135 4.398647 4.103622 3.905996 3.768078 4.032471 4.215768
## 441 442 443 444 445 446 447 448
## 4.025720 4.284032 4.368999 3.772021 3.804049 3.895453 3.929298 4.046546
## 449 450 451 452 453 454 455 456
## 4.043920 4.101231 3.766176 4.198135 4.374355 3.843335 4.126996 3.761152
## 457 458 459 460 461 462 463 464
## 3.811881 4.309889 4.154997 3.639441 4.022338 3.791870 3.909534 4.162412
## 465 466 467 468 469 470 471 472
## 4.392066 4.213630 3.832140 4.124599 3.954008 4.126501 3.619358 3.908381
## 473 474 475 476 477 478 479 480
## 3.629158 3.958615 4.118688 3.816247 4.220290 3.737602 3.752759 4.177804
## 481 482 483 484 485 486 487 488
## 4.006620 4.051323 3.686312 4.156893 4.040134 3.462087 4.416678 3.966350
## 489 490 491 492 493 494 495 496
## 3.570525 4.630034 3.707549 4.369487 4.419558 4.108959 4.184229 3.766188
## 497 498 499 500 501 502 503 504
## 4.265174 3.712736 3.564770 4.461230 4.096949 3.952347 3.889934 3.988994
## 505 506 507 508 509 510 511 512
## 3.859548 3.729124 3.832544 4.224076 3.731763 4.023081 3.944690 3.941810
## 513 514 515 516 517 518 519 520
## 3.615734 4.317539 3.982485 4.426563 3.879481 4.103030 3.800595 4.356409
## 521 522 523 524 525 526 527 528
## 4.087885 4.028105 3.840690 3.952027 4.156561 3.967087 3.977461 3.663160
## 529 530 531 532 533 534 535 536
## 3.690086 4.065646 3.931768 4.025388 4.087716 3.829332 4.163722 4.110439
## 537 538 539 540 541 542 543 544
## 4.288222 3.974671 3.916527 4.374355 4.118023 3.983807 3.872730 4.251914
## 545 546 547 548 549 550 551 552
## 4.034113 3.753320 4.200695 4.163475 3.874125 3.935626 4.037489 4.174513
## 553 554 555 556 557 558 559 560
## 3.880967 4.079245 3.856825 4.051570 3.820033 4.132516 3.928803 4.078339
## 561 562 563 564 565 566 567 568
## 3.809484 4.088791 3.847363 3.828752 4.156730 3.781157 3.534548 3.746165
## 569 570 571 572 573 574 575 576
## 3.703424 3.960420 3.981005 4.331699 4.106079 3.495340 4.059149 4.020207
## 577 578 579 580 581 582 583 584
## 4.108549 4.293071 3.754069 3.771435 3.868932 3.479036 3.938441 4.271514
## 585 586 587 588 589 590 591 592
## 4.020533 4.395683 3.478710 3.626271 3.703092 4.067138 4.537652 4.045321
## 593 594 595 596 597 598 599 600
## 3.790722 3.930113 3.864983 4.283941 3.918918 4.206456 4.246727 4.087729
## 601 602 603 604 605 606 607 608
## 4.180521 4.467075 4.253321 4.308077 4.283941 4.029506 4.207193 4.034035
## 609 610 611 612 613 614 615 616
## 3.750367 4.203733 3.824230 3.912741 4.096044 4.058327 3.617957 3.869844
## 617 618 619 620 621 622 623 624
## 4.007285 3.801990 4.199295 3.840533 4.062772 3.760168 3.833522 3.685557
## 625 626 627 628 629 630 631 632
## 4.089794 4.262046 3.908635 3.870339 4.241051 4.008752 3.613265 3.925669
## 633 634 635 636 637 638 639 640
## 3.622981 3.953096 3.814508 3.624642 3.552742 4.295149 4.048116 4.334912
## 641 642 643 644 645 646 647 648
## 4.105506 3.484326 3.766587 3.685485 3.748888 3.769147 3.976386 4.110608
## 649 650 651 652 653 654 655 656
## 3.620348 4.042923 3.830818 4.076944 3.785112 3.584606 3.891165 4.294315
## 657 658 659 660 661 662 663 664
## 4.081135 3.760651 3.864325 4.121067 4.117365 3.993855 4.116622 3.618373
## 665 666 667 668 669 670 671 672
## 4.085579 3.997550 4.196499 4.394692 4.154345 3.907729 4.351711 4.100566
## 673 674 675 676 677 678 679 680
## 4.391238 4.042851 3.733393 4.084679 3.702688 3.855931 4.148161 3.885157
## 681 682 683 684 685 686 687 688
## 3.829169 4.308409 4.311453 3.736775 4.098422 4.438416 3.693232 3.936369
## 689 690 691 692 693 694 695 696
## 4.145365 3.569136 3.946345 4.172617 4.048279 3.777221 4.414202 4.057337
## 697 698 699 700 701 702 703 704
## 4.493916 4.368184 3.516016 4.309798 3.964134 4.073725 4.176312 4.378056
## 705 706 707 708 709 710 711 712
## 4.451520 3.738254 3.767166 3.916038 4.155238 4.092740 3.710846 3.920156
## 713 714 715 716 717 718 719 720
## 4.186046 3.893980 3.719813 4.055037 3.793427 4.247137 4.132196 3.778603
## 721 722 723 724 725 726 727 728
## 3.919413 3.713805 4.299841 4.120499 4.413387 3.781731 3.730102 4.221208
## 729 730 731 732 733 734 735 736
## 3.854693 3.902784 4.008184 4.275868 3.839380 3.477569 3.872066 4.434129
## 737 738 739 740 741 742 743 744
## 3.858395 4.424426 4.244420 4.616188 4.066069 4.320576 3.941973 4.032725
## 745 746 747 748 749 750 751 752
## 4.208606 4.245072 3.704336 3.741557 4.306748 4.084262 4.406226 3.976398
## 753 754 755 756 757 758 759 760
## 4.693269 3.555459 4.201770 3.681113 3.429648 4.303536 3.742046 4.036022
## 761 762 763 764 765 766 767 768
## 3.903103 3.691408 4.207622 3.788736 3.938030 4.021589 3.965855 3.906159
## 769 770 771 772 773 774 775 776
## 4.561763 4.299013 4.108724 4.250923 4.069275 4.121242 3.705907 3.560900
## 777 778 779 780 781 782 783 784
## 3.967093 3.488185 4.185376 4.389674 3.902699 3.975408 4.201680 4.259081
## 785 786 787 788 789 790 791 792
## 4.103609 4.225236 4.082868 3.841282 3.882355 3.844313 3.678884 4.173939
## 793 794 795 796 797 798 799 800
## 4.352701 3.984121 3.850672 4.060139 3.638469 3.896437 3.419184 4.038159
## 801 802 803 804 805 806 807 808
## 3.977962 3.942214 3.966761 4.095711 4.170727 4.175745 3.978373 3.718177
## 809 810 811 812 813 814 815 816
## 4.119333 3.913731 4.177725 3.655914 3.974411 3.959352 4.222681 3.540888
## 817 818 819 820 821 822 823 824
## 4.210248 3.995002 3.918761 3.992859 3.969635 3.758689 3.923369 4.138771
## 825 826 827 828 829 830 831 832
## 3.953506 3.711667 4.272589 4.086328 3.888865 3.812122 3.512399 4.318940
## 833 834 835 836 837 838 839 840
## 4.280246 3.787836 3.876347 4.225731 4.295879 3.802902 4.220218 3.962395
## 841 842 843 844 845 846 847 848
## 3.913659 3.728538 4.267155 4.533939 4.052065 4.323228 4.087807 3.820842
## 849 850 851 852 853 854 855 856
## 4.039137 3.988584 4.276200 4.014356 3.980921 4.015835 3.646772 4.129466
## 857 858 859 860 861 862 863 864
## 3.929142 4.592898 4.387042 4.005298 4.102625 4.427390 4.022906 4.244504
## 865 866 867 868 869 870 871 872
## 4.092342 3.947238 4.236020 3.808173 3.878412 3.961235 3.673540 4.028769
## 873 874 875 876 877 878 879 880
## 4.323547 4.317702 4.017477 3.876679 4.187526 3.929866 4.273241 3.814592
## 881 882 883 884 885 886 887 888
## 4.214439 4.071920 3.797624 4.100500 4.185877 4.169085 3.495105 4.083936
## 889 890 891 892 893 894 895 896
## 4.580628 4.031148 4.379457 3.994435 3.974001 4.157219 3.474683 4.435621
## 897 898 899 900 901 902 903 904
## 3.551419 3.959436 3.906153 4.215442 4.058810 3.903435 4.448966 3.972280
## 905 906 907 908 909 910 911 912
## 3.690502 3.989320 3.888122 4.225966 3.947329 3.772933 4.024234 4.013860
## 913 914 915 916 917 918 919 920
## 3.899076 4.291852 3.951767 3.746412 4.224734 3.760331 3.772855 4.018311
## 921 922 923 924 925 926 927 928
## 3.924190 3.703841 3.537181 4.255863 3.955722 4.086491 3.944859 3.941399
## 929 930 931 932 933 934 935 936
## 3.915301 4.236763 4.071262 3.556280 3.643807 4.038811 4.360025 4.476869
## 937 938 939 940 941 942 943 944
## 3.800015 4.230410 4.032966 3.856505 4.092656 3.735295 3.675600 4.169495
## 945 946 947 948 949 950 951 952
## 4.292262 4.326102 4.308397 4.252735 3.761237 4.324212 3.948319 4.238985
## 953 954 955 956 957 958 959 960
## 3.974496 4.109944 4.285095 4.075452 3.908466 3.976144 3.695768 3.824888
## 961 962 963 964 965 966 967 968
## 3.755874 3.594739 3.843088 3.744594 3.785940 3.933163 3.864240 3.625535
## 969 970 971 972 973 974 975 976
## 4.067548 3.763374 4.331796 4.080476 4.118942 4.269364 3.894964 4.130789
## 977 978 979 980 981 982 983 984
## 3.685889 3.962570 3.870417 4.280898 4.172200 3.593736 4.144786 4.013933
## 985 986 987 988 989 990 991 992
## 3.822503 4.329562 3.919824 3.988251 3.867289 3.544101 4.050260 3.963633
## 993 994 995 996 997 998 999 1000
## 4.006451 4.071829 4.370569 3.701202 4.275379 3.868189 4.296381 4.157134
yhat.model1 <- fitted.values(model1) # create new variable where we look at predicted vs actual variables
plot(yhat.model1, clean.dat$GPA, xlab = "Fitted Values", ylab = "Observed Values") # looks linear, positive correlation
#### 9. Outliers & Influential Cases ####
#Standardized residuals (z-score)
rstandard(model = model1)
## 1 2 3 4 5 6
## -1.359091074 1.015595927 -0.518817205 0.116613697 0.970853079 0.426157696
## 7 8 9 10 11 12
## -0.381996852 1.975682402 -0.132702189 -0.401082045 0.087201739 0.552150073
## 13 14 15 16 17 18
## -0.917299682 -0.434572445 -0.215308491 0.892747179 0.650125833 -1.438009678
## 19 20 21 22 23 24
## 1.436898885 0.493979037 0.097380335 0.471738681 -0.688743505 -0.961978286
## 25 26 27 28 29 30
## 0.320826970 -1.415431148 -1.190101676 0.145866902 -0.020643807 -2.035486148
## 31 32 33 34 35 36
## -0.216564938 0.536802566 0.905311647 1.321840173 0.296845767 0.260746949
## 37 38 39 40 41 42
## -1.957936868 -2.198492713 0.591885665 -0.351580312 1.049992372 0.671606625
## 43 44 45 46 47 48
## -0.834375070 0.730540208 0.864653548 0.475011646 0.650446600 0.283316267
## 49 50 51 52 53 54
## 0.434888269 -1.457289220 -0.721561289 -0.867930678 0.444162416 -0.353222427
## 55 56 57 58 59 60
## 0.944948325 -0.022076359 1.274095741 -0.432434331 1.577905865 -0.035133528
## 61 62 63 64 65 66
## 1.702310869 -0.237847931 -2.244778917 -0.328460789 0.474876504 0.977908832
## 67 68 69 70 71 72
## 0.971746058 -1.109076356 -0.129224969 -2.017803195 -0.761682240 -0.134531765
## 73 74 75 76 77 78
## 1.475944337 1.244673977 0.851409623 0.096028434 0.118409102 -0.025047880
## 79 80 81 82 83 84
## 0.642564141 0.088813245 0.124206385 -0.395279929 -0.910145192 -0.485243250
## 85 86 87 88 89 90
## -1.053552340 -0.123069873 0.602132317 -1.045541958 1.232306867 0.399871534
## 91 92 93 94 95 96
## 0.953335098 0.116093238 -0.385645283 0.667399308 -1.456770385 -0.092831577
## 97 98 99 100 101 102
## -0.845036953 -0.537872228 1.082138499 1.658916632 -0.147558741 -1.781423870
## 103 104 105 106 107 108
## -0.341779457 0.390785973 -0.806858055 1.560072493 0.853849055 -0.912774561
## 109 110 111 112 113 114
## -0.710843354 0.905610248 -0.467295318 1.152867502 1.174563311 -2.452697901
## 115 116 117 118 119 120
## -0.885182257 -1.157797114 -1.729663876 -0.007788866 0.890978388 0.376062856
## 121 122 123 124 125 126
## -2.129868393 0.388830931 -0.872960996 -0.927545480 0.392222157 0.643854388
## 127 128 129 130 131 132
## -1.131448323 -1.167290588 -0.628650700 0.347218304 -1.692412663 -0.152345223
## 133 134 135 136 137 138
## 2.435603350 -2.141669456 1.186805956 -0.556951012 0.750343452 -0.863756005
## 139 140 141 142 143 144
## 0.646390229 0.388913876 0.091904499 -0.750291573 1.791590385 -0.235960449
## 145 146 147 148 149 150
## 1.367136230 -0.598913763 -0.292062340 -0.072564769 0.521282110 1.209597942
## 151 152 153 154 155 156
## -0.053677114 -1.125643299 -0.395464522 -0.849700567 -0.141857283 0.321423261
## 157 158 159 160 161 162
## -0.329084837 0.653595456 -0.820605052 -0.955917545 0.785668006 0.631757011
## 163 164 165 166 167 168
## -1.526530201 0.777204172 -0.202912334 -0.434480948 -0.283227060 -0.457606047
## 169 170 171 172 173 174
## -0.177279129 0.975043094 -0.084087422 0.757496201 0.494905966 -0.455906528
## 175 176 177 178 179 180
## 0.354549587 0.460460265 -0.812768179 0.086588079 -0.837427409 1.128806808
## 181 182 183 184 185 186
## 0.686089816 0.578352726 -0.628279763 -1.533391735 1.243651974 3.175866638
## 187 188 189 190 191 192
## 0.200327520 -1.481229119 1.135511464 -0.714505190 -0.336849009 2.141407168
## 193 194 195 196 197 198
## 0.590833056 -1.198347463 -0.965698148 -0.598525395 -1.744806780 0.849759836
## 199 200 201 202 203 204
## 0.664223533 -0.009509058 -0.772908121 -0.451131857 0.802461244 -0.309832696
## 205 206 207 208 209 210
## -1.165382232 -0.732457825 -1.648508327 2.775541990 0.871856333 0.153590176
## 211 212 213 214 215 216
## -0.829770045 -0.537211096 -0.048879366 1.686725219 -1.006347843 -1.047298159
## 217 218 219 220 221 222
## -1.603585932 -1.313332758 -0.253112259 0.146860145 0.587251909 0.331241124
## 223 224 225 226 227 228
## -0.512836315 -0.109224698 -0.040079796 0.133147079 1.236207605 0.252803708
## 229 230 231 232 233 234
## -1.390600443 0.859679358 1.082206263 -0.642132973 1.757209650 0.143590255
## 235 236 237 238 239 240
## 0.818886905 1.722547713 -0.979566838 -0.089487486 -0.502460059 -1.315503075
## 241 242 243 244 245 246
## 0.309423972 -0.114984790 -0.317492849 -1.844763669 -0.391430273 -1.065445478
## 247 248 249 250 251 252
## -0.906636819 0.192212192 -1.049547193 -1.703885753 0.131925572 0.546184265
## 253 254 255 256 257 258
## -0.025705425 -0.083201195 -0.091119942 0.882016946 -1.887544666 -1.208427586
## 259 260 261 262 263 264
## -0.981661004 1.823518048 -0.344155661 -2.934940420 1.304963299 -0.094997707
## 265 266 267 268 269 270
## -0.967761044 0.318050780 -1.321881620 1.127878405 0.601418627 -0.402327858
## 271 272 273 274 275 276
## 0.787438999 1.308903506 0.649756965 -0.995392345 0.238068843 1.891250492
## 277 278 279 280 281 282
## 1.798991305 -0.071452593 -0.196246723 -0.223658368 0.532419154 0.796611195
## 283 284 285 286 287 288
## -0.181714034 0.409713766 1.148406504 -1.711902592 1.760982819 1.825320279
## 289 290 291 292 293 294
## -0.579472300 -1.188091229 1.533259455 0.378141880 -1.124314298 0.875822755
## 295 296 297 298 299 300
## -1.065749918 0.038581803 2.179896078 2.364442015 0.362404152 0.144544584
## 301 302 303 304 305 306
## 2.135986568 1.033505366 0.561230522 -0.475073201 1.539121826 -0.548813497
## 307 308 309 310 311 312
## -1.018482051 0.061507594 -0.949047541 1.043825585 -2.666722085 0.850864111
## 313 314 315 316 317 318
## -0.172115429 -0.728010665 -1.655099980 0.748820210 -2.319415613 -0.920355223
## 319 320 321 322 323 324
## 0.590496092 1.285544830 -1.218248518 -1.149921350 -1.043789072 2.136958389
## 325 326 327 328 329 330
## -1.308200203 0.705728842 -0.007774010 -1.769913558 1.498583923 -0.468372215
## 331 332 333 334 335 336
## -1.622555431 -0.156000147 -0.871814322 1.065418850 1.192910175 -0.201763986
## 337 338 339 340 341 342
## 0.438819369 -0.475709544 0.423959515 -1.175483064 -0.475998356 0.563399542
## 343 344 345 346 347 348
## 0.501898281 0.616015860 1.235560730 0.045441304 -0.974988294 -2.219154487
## 349 350 351 352 353 354
## -0.716811153 -0.583455681 0.551396053 -0.972188655 -0.149209935 0.499410573
## 355 356 357 358 359 360
## -0.283941735 0.686332084 -1.533242957 -0.219454014 1.119296676 0.201372273
## 361 362 363 364 365 366
## 0.748773981 0.630595366 -0.568644477 0.900401428 0.514719790 0.938649260
## 367 368 369 370 371 372
## 0.154263231 0.457983913 -1.355569384 0.386443946 0.424569973 2.231785841
## 373 374 375 376 377 378
## 1.142763625 1.666874835 -1.320227344 -0.297908418 1.486513421 0.876813627
## 379 380 381 382 383 384
## 1.088612279 -0.997457707 -0.048617864 -0.490600810 -1.249593869 0.774586961
## 385 386 387 388 389 390
## -1.301616061 0.066418708 1.203265738 1.294476669 -0.305396674 0.773531967
## 391 392 393 394 395 396
## -1.218924813 -0.288219726 0.604552233 -0.931049929 -0.513119672 -0.487933264
## 397 398 399 400 401 402
## -1.058986047 -1.031555491 -1.146078603 -1.069668855 1.622915816 2.111848031
## 403 404 405 406 407 408
## -1.479322985 -0.744406037 0.094336625 -2.006895522 0.229009275 -0.617508932
## 409 410 411 412 413 414
## 1.045916346 1.315540257 -0.931501609 -0.432145631 -0.166662668 0.503125157
## 415 416 417 418 419 420
## 1.083991646 0.599519434 -1.928817779 0.929933917 2.003713614 0.435518112
## 421 422 423 424 425 426
## 0.225093491 -1.060341134 1.902075272 -0.376295417 -1.202887106 0.273365374
## 427 428 429 430 431 432
## 2.213801642 0.367764657 -0.722828114 0.819817940 -1.424477458 -1.174506190
## 433 434 435 436 437 438
## -0.440586939 0.396298332 0.003103732 0.909407294 -1.320413194 0.371856899
## 439 440 441 442 443 444
## 2.056898973 -0.380083801 0.284827324 1.528008017 -1.099542069 0.545616629
## 445 446 447 448 449 450
## 0.220016386 1.110548656 0.872629245 1.544030581 -0.902992818 0.295218889
## 451 452 453 454 455 456
## -1.160561445 0.807699917 -0.445925413 1.299580426 0.213205908 -0.048497477
## 457 458 459 460 461 462
## -0.944812295 0.734731469 0.286527526 -0.458220002 0.590674924 -0.027218723
## 463 464 465 466 467 468
## 1.949215306 0.934719523 0.729950129 -1.568334702 0.408274615 1.460777008
## 469 470 471 472 473 474
## -0.445370543 0.053878312 1.171668511 2.547718438 -0.273389772 1.149715632
## 475 476 477 478 479 480
## 0.209368172 0.742959526 2.177782363 0.234801293 0.039554463 1.357511758
## 481 482 483 484 485 486
## -1.482693481 -0.622008256 -0.427973312 -1.895654910 -0.573551043 -0.257508566
## 487 488 489 490 491 492
## 0.466647820 -0.220810191 -0.690054970 0.206917521 -1.072306758 -1.194297100
## 493 494 495 496 497 498
## 0.574916301 1.241196387 0.655095497 1.849077780 -1.388019476 1.002794920
## 499 500 501 502 503 504
## 0.838677094 0.777757804 -0.612065826 -0.693169324 -2.383677841 1.766934484
## 505 506 507 508 509 510
## -0.847199132 2.272656303 0.842332526 0.174150810 0.248439016 -1.726041739
## 511 512 513 514 515 516
## 0.493546839 1.325156697 1.248844641 -0.086099367 -0.372481528 0.375116556
## 517 518 519 520 521 522
## 0.551358670 -0.236432211 0.319587644 0.604787503 -0.934848469 -0.087329068
## 523 524 525 526 527 528
## -1.239906840 0.018280838 0.191255727 -0.497652629 -1.140602447 1.920291687
## 529 530 531 532 533 534
## -0.573850663 0.675551037 1.096121897 -0.676968616 -0.040629798 -0.342310713
## 535 536 537 538 539 540
## 0.679187608 0.871529883 -0.362928797 -0.721473864 -0.886370839 1.596081032
## 541 542 543 544 545 546
## 0.394170485 0.220451499 -2.161442621 0.408329673 -0.078203208 -0.237312186
## 547 548 549 550 551 552
## 0.250575746 -0.718646081 -0.032375424 -1.229624588 -0.361071535 -0.514669755
## 553 554 555 556 557 558
## 0.754703474 -0.663057838 -0.842171419 -0.278677670 0.321060516 0.727696054
## 559 560 561 562 563 564
## -0.914034007 -0.179582114 -0.021745426 1.034144136 1.083445531 0.186276097
## 565 566 567 568 569 570
## -0.726272936 -0.874128050 -1.870203834 0.673767126 -0.420910306 1.305341982
## 571 572 573 574 575 576
## 0.662313982 -0.026841655 0.375898671 0.816245751 -0.020966796 0.160033998
## 577 578 579 580 581 582
## 1.081253759 -0.904351437 -0.490861806 3.212140482 0.323594582 -0.204940695
## 583 584 585 586 587 588
## -1.280440943 1.326840927 -0.872143828 0.675340307 -0.571824149 -0.679932122
## 589 590 591 592 593 594
## 2.013751790 -1.322694885 -0.293883089 -0.058053813 0.457599160 -1.903568273
## 595 596 597 598 599 600
## -1.020123797 -0.307204924 -0.043361150 -0.198257802 0.810006148 0.051081258
## 601 602 603 604 605 606
## -1.330759153 -0.842721095 1.277806328 -0.615295750 0.128575215 0.092801330
## 607 608 609 610 611 612
## 1.131271551 -1.292617373 0.136743493 -1.570450890 -0.468240845 0.773167204
## 613 614 615 616 617 618
## -0.013856835 -2.815149073 -0.224777093 0.229563223 0.741265173 -1.449282706
## 619 620 621 622 623 624
## 1.193746970 -0.551447733 0.039484066 -0.023319316 -0.696736397 0.744488965
## 625 626 627 628 629 630
## 0.874184268 -1.748112654 0.232552573 0.618080841 1.030171638 -0.593169139
## 631 632 633 634 635 636
## -0.236946785 0.239157706 -1.635896675 -0.373854334 -0.698127476 0.035351565
## 637 638 639 640 641 642
## 1.279272684 0.378299460 -0.866561244 -2.741194054 -0.379372439 1.140362950
## 643 644 645 646 647 648
## 0.328812247 -1.320569903 -0.915036264 0.093768671 0.559261621 0.801223922
## 649 650 651 652 653 654
## 0.458106488 -1.153049945 0.204480428 0.902073149 0.538520385 -0.423773361
## 655 656 657 658 659 660
## 1.625523764 1.710635025 1.785028204 -0.873657455 0.723643545 1.694211246
## 661 662 663 664 665 666
## -0.979505332 0.587126476 0.351563009 0.967576537 0.629007503 -1.416491137
## 667 668 669 670 671 672
## 0.030952928 0.103976836 -0.170580628 0.854068316 -1.908008818 1.007175826
## 673 674 675 676 677 678
## -0.530611666 -0.533922407 0.612402482 -0.583823930 -0.533658203 0.674154115
## 679 680 681 682 683 684
## 0.256347511 -1.501801866 1.491991964 0.509018086 -1.288509959 -0.221974306
## 685 686 687 688 689 690
## -0.340283681 -0.547278543 -1.249480091 -0.381720898 -1.089822384 1.472091467
## 691 692 693 694 695 696
## -1.390125767 0.200305091 1.012326117 -1.786405221 0.334971511 0.120692759
## 697 698 699 700 701 702
## 0.725842978 -0.271179851 1.432987500 -1.444526100 0.839423786 1.389512896
## 703 704 705 706 707 708
## 0.100357021 -1.143356490 1.237895302 -1.763148473 -0.291617499 0.054918191
## 709 710 711 712 713 714
## -0.493585493 0.177146007 -2.135727669 1.191408893 0.169694119 -0.238682870
## 715 716 717 718 719 720
## 0.803226164 0.882538827 -0.718664298 -0.337359352 0.293328352 -0.868546840
## 721 722 723 724 725 726
## -1.350872126 1.917638102 0.413305673 0.113499634 0.198764782 1.372831553
## 727 728 729 730 731 732
## 0.527633342 1.007456283 -0.354576811 0.268676118 -0.935860272 0.537373536
## 733 734 735 736 737 738
## 0.528691564 -0.729689971 -0.027656614 1.713902185 0.439292751 -1.709284956
## 739 740 741 742 743 744
## 1.090409638 0.791363154 -0.976574188 0.067623515 -0.233748732 1.025993763
## 745 746 747 748 749 750
## 0.186682181 -0.309966896 -0.308086215 -0.783295891 0.604007470 0.334019773
## 751 752 753 754 755 756
## -0.519207984 -0.908562187 -0.329608114 -0.219136156 -0.210438081 -1.310115643
## 757 758 759 760 761 762
## 0.230795931 2.126128584 0.431018525 0.766948629 0.658174308 0.409605212
## 763 764 765 766 767 768
## -0.912898332 1.057515746 0.646678027 0.823576576 -0.036335427 0.581809578
## 769 770 771 772 773 774
## -1.222166377 1.240670788 0.965921516 -1.997029264 -0.433831680 0.455886663
## 775 776 777 778 779 780
## -0.610253866 0.617894440 0.212937977 -0.363333471 0.698562976 -3.028294758
## 781 782 783 784 785 786
## -1.175055883 -1.502022901 -0.439584140 -1.305316663 -0.352213130 -1.456429574
## 787 788 789 790 791 792
## 0.360207741 -0.370513328 -0.464003428 -0.147481323 -0.824097459 -0.421795842
## 793 794 795 796 797 798
## -1.589065217 0.427704407 -0.898619828 -0.642038985 -0.019450688 0.948113221
## 799 800 801 802 803 804
## -0.779477876 0.440058474 -0.384956362 0.040822630 -2.307248406 1.247523020
## 805 806 807 808 809 810
## -0.735339450 0.880862024 1.126697783 0.945336100 -0.962324249 -2.369284706
## 811 812 813 814 815 816
## 0.738852946 -0.105362803 -1.134384889 -2.542411761 0.681635912 1.054069840
## 817 818 819 820 821 822
## 1.627121704 1.661661296 -1.785871336 -0.075339962 -1.169513909 -1.121392466
## 823 824 825 826 827 828
## 1.115340229 0.690570261 -0.535189644 1.487037045 -1.636067374 -0.335534104
## 829 830 831 832 833 834
## -0.203675137 -1.196912616 -0.327043381 -0.869127264 0.343727107 -0.407882333
## 835 836 837 838 839 840
## 0.764798905 -1.067896768 2.005477415 -0.029579113 0.963180679 -0.349283997
## 841 842 843 844 845 846
## -0.582133218 0.668840215 0.465712793 1.576056151 -1.104906139 -0.902489485
## 847 848 849 850 851 852
## -0.086657913 -1.471092957 -0.204313995 0.140755663 0.123408705 0.654617872
## 853 854 855 856 857 858
## -0.185488931 0.949252195 -0.474737109 -0.159259901 -0.273634091 -0.650422474
## 859 860 861 862 863 864
## -0.567048177 0.262865221 0.658644148 -1.165177778 0.292199214 0.127250634
## 865 866 867 868 869 870
## 0.407732810 0.947047443 2.095521248 0.027118442 0.232932610 0.088974009
## 871 872 873 874 875 876
## -0.283371846 1.011526076 -1.109360660 1.221005686 -0.819965679 -0.450795735
## 877 878 879 880 881 882
## 1.771439385 -2.889406727 1.139149411 1.319053235 -1.066181392 0.683866908
## 883 884 885 886 887 888
## -1.760893592 0.436090555 1.522613508 -1.122393213 -0.562903963 -0.673699826
## 889 890 891 892 893 894
## -0.047412569 0.180780942 -0.939778527 -1.363386777 -0.674351434 0.900319838
## 895 896 897 898 899 900
## 0.976925444 0.515021883 0.203522603 1.491237478 0.834198479 -1.388967656
## 901 902 903 904 905 906
## 1.334348059 0.129686870 -1.054548984 2.126189193 0.319943016 0.987152594
## 907 908 909 910 911 912
## 1.402516762 -0.518856887 0.212382089 0.062098046 -1.063965647 -0.306772961
## 913 914 915 916 917 918
## -0.570861003 -1.128083353 -1.357758507 -1.000676297 -1.020231254 -1.009680778
## 919 920 921 922 923 924
## 0.751432618 -0.981753787 0.265418932 1.619503045 -0.475638900 -0.128108622
## 925 926 927 928 929 930
## 0.422522647 0.649914733 -0.973705557 2.540689326 -0.539437356 0.374264982
## 931 932 933 934 935 936
## 0.364242903 -0.083305217 -0.399115200 0.002724412 0.091722879 -2.036632138
## 937 938 939 940 941 942
## 0.504368408 -0.690399471 -1.129790834 0.305986337 -0.350193409 0.859239742
## 943 944 945 946 947 948
## 0.744102088 0.184692931 0.958021690 0.215387202 0.462449776 -0.373153905
## 949 950 951 952 953 954
## -1.447423204 0.059152952 1.104061928 0.300384181 1.067452177 0.620362670
## 955 956 957 958 959 960
## -1.158414029 0.331280520 1.264247625 0.627790273 1.523967414 -1.959897522
## 961 962 963 964 965 966
## 0.514497777 -0.722280609 0.887246658 -0.676080567 -0.678556462 1.757694823
## 967 968 969 970 971 972
## 0.448894103 -0.609243016 0.441060238 -0.168236110 0.800449625 -0.757394806
## 973 974 975 976 977 978
## -0.020543178 -2.063336617 0.699469940 0.731658849 -0.082321963 -1.130321688
## 979 980 981 982 983 984
## 0.709711382 -0.483621804 -1.312387015 0.751386514 -1.592509422 0.358445628
## 985 986 987 988 989 990
## -0.143352302 0.482683303 -0.801812907 0.851966925 -0.016709223 -0.261984917
## 991 992 993 994 995 996
## 0.595409944 1.068799201 -0.152289993 -0.852170784 0.251060706 0.777294057
## 997 998 999 1000
## 0.767369866 -0.982675231 -0.450416592 1.061109479
sort(abs(rstandard(model1)))
## 934 435 327 118 200 613
## 0.002724412 0.003103732 0.007774010 0.007788866 0.009509058 0.013856835
## 989 524 797 973 29 575
## 0.016709223 0.018280838 0.019450688 0.020543178 0.020643807 0.020966796
## 561 56 622 78 253 572
## 0.021745426 0.022076359 0.023319316 0.025047880 0.025705425 0.026841655
## 868 462 735 838 667 549
## 0.027118442 0.027218723 0.027656614 0.029579113 0.030952928 0.032375424
## 60 636 767 296 621 479
## 0.035133528 0.035351565 0.036335427 0.038581803 0.039484066 0.039554463
## 225 533 802 597 346 889
## 0.040079796 0.040629798 0.040822630 0.043361150 0.045441304 0.047412569
## 456 381 213 600 151 470
## 0.048497477 0.048617864 0.048879366 0.051081258 0.053677114 0.053878312
## 708 592 950 308 910 386
## 0.054918191 0.058053813 0.059152952 0.061507594 0.062098046 0.066418708
## 742 278 148 820 545 977
## 0.067623515 0.071452593 0.072564769 0.075339962 0.078203208 0.082321963
## 254 932 171 514 178 847
## 0.083201195 0.083305217 0.084087422 0.086099367 0.086588079 0.086657913
## 11 522 80 870 238 255
## 0.087201739 0.087329068 0.088813245 0.088974009 0.089487486 0.091119942
## 935 141 606 96 646 405
## 0.091722879 0.091904499 0.092801330 0.092831577 0.093768671 0.094336625
## 264 76 21 703 668 812
## 0.094997707 0.096028434 0.097380335 0.100357021 0.103976836 0.105362803
## 224 724 242 92 4 77
## 0.109224698 0.113499634 0.114984790 0.116093238 0.116613697 0.118409102
## 696 86 851 81 864 924
## 0.120692759 0.123069873 0.123408705 0.124206385 0.127250634 0.128108622
## 605 69 902 251 9 226
## 0.128575215 0.129224969 0.129686870 0.131925572 0.132702189 0.133147079
## 72 609 850 155 985 234
## 0.134531765 0.136743493 0.140755663 0.141857283 0.143352302 0.143590255
## 300 28 220 790 101 353
## 0.144544584 0.145866902 0.146860145 0.147481323 0.147558741 0.149209935
## 993 132 210 367 332 856
## 0.152289993 0.152345223 0.153590176 0.154263231 0.156000147 0.159259901
## 576 413 970 713 669 313
## 0.160033998 0.166662668 0.168236110 0.169694119 0.170580628 0.172115429
## 508 710 169 560 890 283
## 0.174150810 0.177146007 0.177279129 0.179582114 0.180780942 0.181714034
## 944 853 564 745 525 248
## 0.184692931 0.185488931 0.186276097 0.186682181 0.191255727 0.192212192
## 279 598 725 692 187 360
## 0.196246723 0.198257802 0.198764782 0.200305091 0.200327520 0.201372273
## 336 165 897 829 849 651
## 0.201763986 0.202912334 0.203522603 0.203675137 0.204313995 0.204480428
## 582 490 475 755 909 777
## 0.204940695 0.206917521 0.209368172 0.210438081 0.212382089 0.212937977
## 455 15 946 31 754 358
## 0.213205908 0.215308491 0.215387202 0.216564938 0.219136156 0.219454014
## 445 542 488 684 280 615
## 0.220016386 0.220451499 0.220810191 0.221974306 0.223658368 0.224777093
## 421 407 616 757 627 869
## 0.225093491 0.229009275 0.229563223 0.230795931 0.232552573 0.232932610
## 743 478 144 518 631 546
## 0.233748732 0.234801293 0.235960449 0.236432211 0.236946785 0.237312186
## 62 275 714 632 509 547
## 0.237847931 0.238068843 0.238682870 0.239157706 0.248439016 0.250575746
## 995 228 219 679 486 36
## 0.251060706 0.252803708 0.253112259 0.256347511 0.257508566 0.260746949
## 990 860 921 730 698 426
## 0.261984917 0.262865221 0.265418932 0.268676118 0.271179851 0.273365374
## 473 857 556 167 48 871
## 0.273389772 0.273634091 0.278677670 0.283227060 0.283316267 0.283371846
## 355 441 459 392 707 147
## 0.283941735 0.284827324 0.286527526 0.288219726 0.291617499 0.292062340
## 863 719 591 450 35 376
## 0.292199214 0.293328352 0.293883089 0.295218889 0.296845767 0.297908418
## 952 389 940 912 596 747
## 0.300384181 0.305396674 0.305986337 0.306772961 0.307204924 0.308086215
## 241 204 746 243 266 519
## 0.309423972 0.309832696 0.309966896 0.317492849 0.318050780 0.319587644
## 905 25 557 156 581 831
## 0.319943016 0.320826970 0.321060516 0.321423261 0.323594582 0.327043381
## 64 643 157 753 222 956
## 0.328460789 0.328812247 0.329084837 0.329608114 0.331241124 0.331280520
## 750 695 828 191 718 685
## 0.334019773 0.334971511 0.335534104 0.336849009 0.337359352 0.340283681
## 103 534 833 261 130 840
## 0.341779457 0.342310713 0.343727107 0.344155661 0.347218304 0.349283997
## 941 663 40 785 54 175
## 0.350193409 0.351563009 0.351580312 0.352213130 0.353222427 0.354549587
## 729 984 787 551 299 537
## 0.354576811 0.358445628 0.360207741 0.361071535 0.362404152 0.362928797
## 778 931 428 788 438 515
## 0.363333471 0.364242903 0.367764657 0.370513328 0.371856899 0.372481528
## 948 634 930 516 573 120
## 0.373153905 0.373854334 0.374264982 0.375116556 0.375898671 0.376062856
## 424 292 638 641 440 688
## 0.376295417 0.378141880 0.378299460 0.379372439 0.380083801 0.381720898
## 7 801 93 370 122 140
## 0.381996852 0.384956362 0.385645283 0.386443946 0.388830931 0.388913876
## 104 245 125 541 82 153
## 0.390785973 0.391430273 0.392222157 0.394170485 0.395279929 0.395464522
## 434 933 90 10 270 865
## 0.396298332 0.399115200 0.399871534 0.401082045 0.402327858 0.407732810
## 834 467 544 762 284 723
## 0.407882333 0.408274615 0.408329673 0.409605212 0.409713766 0.413305673
## 569 792 925 654 339 371
## 0.420910306 0.421795842 0.422522647 0.423773361 0.423959515 0.424569973
## 6 794 483 759 412 58
## 0.426157696 0.427704407 0.427973312 0.431018525 0.432145631 0.432434331
## 773 166 14 49 420 884
## 0.433831680 0.434480948 0.434572445 0.434888269 0.435518112 0.436090555
## 337 737 783 800 433 969
## 0.438819369 0.439292751 0.439584140 0.440058474 0.440586939 0.441060238
## 53 469 453 967 999 876
## 0.444162416 0.445370543 0.445925413 0.448894103 0.450416592 0.450795735
## 202 774 174 593 168 368
## 0.451131857 0.455886663 0.455906528 0.457599160 0.457606047 0.457983913
## 649 460 176 947 789 843
## 0.458106488 0.458220002 0.460460265 0.462449776 0.464003428 0.465712793
## 487 111 611 330 22 855
## 0.466647820 0.467295318 0.468240845 0.468372215 0.471738681 0.474737109
## 65 46 304 923 338 341
## 0.474876504 0.475011646 0.475073201 0.475638900 0.475709544 0.475998356
## 986 980 84 396 382 579
## 0.482683303 0.483621804 0.485243250 0.487933264 0.490600810 0.490861806
## 511 709 20 173 526 354
## 0.493546839 0.493585493 0.493979037 0.494905966 0.497652629 0.499410573
## 343 239 414 937 682 223
## 0.501898281 0.502460059 0.503125157 0.504368408 0.509018086 0.512836315
## 395 961 552 365 896 3
## 0.513119672 0.514497777 0.514669755 0.514719790 0.515021883 0.518817205
## 908 751 149 727 733 673
## 0.518856887 0.519207984 0.521282110 0.527633342 0.528691564 0.530611666
## 281 677 674 825 32 212
## 0.532419154 0.533658203 0.533922407 0.535189644 0.536802566 0.537211096
## 732 98 653 929 444 252
## 0.537373536 0.537872228 0.538520385 0.539437356 0.545616629 0.546184265
## 686 306 517 351 620 12
## 0.547278543 0.548813497 0.551358670 0.551396053 0.551447733 0.552150073
## 136 647 303 887 342 859
## 0.556951012 0.559261621 0.561230522 0.562903963 0.563399542 0.567048177
## 363 913 587 485 529 493
## 0.568644477 0.570861003 0.571824149 0.573551043 0.573850663 0.574916301
## 182 289 768 841 350 676
## 0.578352726 0.579472300 0.581809578 0.582133218 0.583455681 0.583823930
## 662 221 319 461 193 39
## 0.587126476 0.587251909 0.590496092 0.590674924 0.590833056 0.591885665
## 630 991 196 146 416 269
## 0.593169139 0.595409944 0.598525395 0.598913763 0.599519434 0.601418627
## 87 749 393 520 968 775
## 0.602132317 0.604007470 0.604552233 0.604787503 0.609243016 0.610253866
## 501 675 604 344 408 776
## 0.612065826 0.612402482 0.615295750 0.616015860 0.617508932 0.617894440
## 628 954 482 958 183 129
## 0.618080841 0.620362670 0.622008256 0.627790273 0.628279763 0.628650700
## 665 362 162 796 232 79
## 0.629007503 0.630595366 0.631757011 0.642038985 0.642132973 0.642564141
## 126 139 765 273 926 17
## 0.643854388 0.646390229 0.646678027 0.649756965 0.649914733 0.650125833
## 858 47 158 852 495 761
## 0.650422474 0.650446600 0.653595456 0.654617872 0.655095497 0.658174308
## 861 571 554 199 94 842
## 0.658644148 0.662313982 0.663057838 0.664223533 0.667399308 0.668840215
## 42 888 568 678 893 586
## 0.671606625 0.673699826 0.673767126 0.674154115 0.674351434 0.675340307
## 530 964 532 965 535 588
## 0.675551037 0.676080567 0.676968616 0.678556462 0.679187608 0.679932122
## 815 882 181 356 23 489
## 0.681635912 0.683866908 0.686089816 0.686332084 0.688743505 0.690054970
## 938 824 502 623 635 779
## 0.690399471 0.690570261 0.693169324 0.696736397 0.698127476 0.698562976
## 975 326 979 109 190 349
## 0.699469940 0.705728842 0.709711382 0.710843354 0.714505190 0.716811153
## 548 717 538 51 962 429
## 0.718646081 0.718664298 0.721473864 0.721561289 0.722280609 0.722828114
## 659 697 565 558 314 734
## 0.723643545 0.725842978 0.726272936 0.727696054 0.728010665 0.729689971
## 465 44 976 206 458 805
## 0.729950129 0.730540208 0.731658849 0.732457825 0.734731469 0.735339450
## 811 617 476 943 404 624
## 0.738852946 0.741265173 0.742959526 0.744102088 0.744406037 0.744488965
## 361 316 142 137 982 919
## 0.748773981 0.748820210 0.750291573 0.750343452 0.751386514 0.751432618
## 553 972 172 71 835 760
## 0.754703474 0.757394806 0.757496201 0.761682240 0.764798905 0.766948629
## 997 201 612 390 384 164
## 0.767369866 0.772908121 0.773167204 0.773531967 0.774586961 0.777204172
## 996 500 799 748 161 271
## 0.777294057 0.777757804 0.779477876 0.783295891 0.785668006 0.787438999
## 740 282 971 648 987 203
## 0.791363154 0.796611195 0.800449625 0.801223922 0.801812907 0.802461244
## 715 105 452 599 177 574
## 0.803226164 0.806858055 0.807699917 0.810006148 0.812768179 0.816245751
## 235 430 875 159 766 791
## 0.818886905 0.819817940 0.819965679 0.820605052 0.823576576 0.824097459
## 211 899 43 179 499 701
## 0.829770045 0.834198479 0.834375070 0.837427409 0.838677094 0.839423786
## 555 507 602 97 505 154
## 0.842171419 0.842332526 0.842721095 0.845036953 0.847199132 0.849700567
## 198 312 75 988 994 107
## 0.849759836 0.850864111 0.851409623 0.851966925 0.852170784 0.853849055
## 670 942 230 138 45 639
## 0.854068316 0.859239742 0.859679358 0.863756005 0.864653548 0.866561244
## 52 720 832 536 333 209
## 0.867930678 0.868546840 0.869127264 0.871529883 0.871814322 0.871856333
## 585 447 123 658 566 625
## 0.872143828 0.872629245 0.872960996 0.873657455 0.874128050 0.874184268
## 294 378 806 256 716 115
## 0.875822755 0.876813627 0.880862024 0.882016946 0.882538827 0.885182257
## 539 963 119 16 795 894
## 0.886370839 0.887246658 0.890978388 0.892747179 0.898619828 0.900319838
## 364 652 846 449 578 33
## 0.900401428 0.902073149 0.902489485 0.902992818 0.904351437 0.905311647
## 110 247 752 436 83 108
## 0.905610248 0.906636819 0.908562187 0.909407294 0.910145192 0.912774561
## 763 559 645 13 318 124
## 0.912898332 0.914034007 0.915036264 0.917299682 0.920355223 0.927545480
## 418 394 411 464 521 731
## 0.929933917 0.931049929 0.931501609 0.934719523 0.934848469 0.935860272
## 366 891 457 55 808 866
## 0.938649260 0.939778527 0.944812295 0.944948325 0.945336100 0.947047443
## 798 309 854 91 160 945
## 0.948113221 0.949047541 0.949252195 0.953335098 0.955917545 0.958021690
## 24 809 839 195 771 664
## 0.961978286 0.962324249 0.963180679 0.965698148 0.965921516 0.967576537
## 265 5 67 352 927 347
## 0.967761044 0.970853079 0.971746058 0.972188655 0.973705557 0.974988294
## 170 741 895 66 661 237
## 0.975043094 0.976574188 0.976925444 0.977908832 0.979505332 0.979566838
## 259 920 998 906 274 380
## 0.981661004 0.981753787 0.982675231 0.987152594 0.995392345 0.997457707
## 916 498 215 672 728 918
## 1.000676297 1.002794920 1.006347843 1.007175826 1.007456283 1.009680778
## 872 693 2 307 595 917
## 1.011526076 1.012326117 1.015595927 1.018482051 1.020123797 1.020231254
## 744 629 398 302 562 323
## 1.025993763 1.030171638 1.031555491 1.033505366 1.034144136 1.043789072
## 310 88 409 216 249 41
## 1.043825585 1.045541958 1.045916346 1.047298159 1.049547193 1.049992372
## 85 816 903 764 397 422
## 1.053552340 1.054069840 1.054548984 1.057515746 1.058986047 1.060341134
## 1000 911 334 246 295 881
## 1.061109479 1.063965647 1.065418850 1.065445478 1.065749918 1.066181392
## 953 836 992 400 491 577
## 1.067452177 1.067896768 1.068799201 1.069668855 1.072306758 1.081253759
## 99 231 563 415 379 689
## 1.082138499 1.082206263 1.083445531 1.083991646 1.088612279 1.089822384
## 739 531 443 951 845 68
## 1.090409638 1.096121897 1.099542069 1.104061928 1.104906139 1.109076356
## 873 446 823 359 822 886
## 1.109360660 1.110548656 1.115340229 1.119296676 1.121392466 1.122393213
## 293 152 807 268 914 180
## 1.124314298 1.125643299 1.126697783 1.127878405 1.128083353 1.128806808
## 939 978 607 127 813 189
## 1.129790834 1.130321688 1.131271551 1.131448323 1.134384889 1.135511464
## 879 642 527 373 704 399
## 1.139149411 1.140362950 1.140602447 1.142763625 1.143356490 1.146078603
## 285 474 322 112 650 116
## 1.148406504 1.149715632 1.149921350 1.152867502 1.153049945 1.157797114
## 955 451 862 205 128 821
## 1.158414029 1.160561445 1.165177778 1.165382232 1.167290588 1.169513909
## 471 432 113 781 340 135
## 1.171668511 1.174506190 1.174563311 1.175055883 1.175483064 1.186805956
## 290 27 712 335 619 492
## 1.188091229 1.190101676 1.191408893 1.192910175 1.193746970 1.194297100
## 830 194 425 387 258 150
## 1.196912616 1.198347463 1.202887106 1.203265738 1.208427586 1.209597942
## 321 391 874 769 550 89
## 1.218248518 1.218924813 1.221005686 1.222166377 1.229624588 1.232306867
## 345 227 705 523 770 494
## 1.235560730 1.236207605 1.237895302 1.239906840 1.240670788 1.241196387
## 185 74 804 513 687 383
## 1.243651974 1.244673977 1.247523020 1.248844641 1.249480091 1.249593869
## 957 57 603 637 583 320
## 1.264247625 1.274095741 1.277806328 1.279272684 1.280440943 1.285544830
## 683 608 388 454 385 263
## 1.288509959 1.292617373 1.294476669 1.299580426 1.301616061 1.304963299
## 784 570 325 272 756 981
## 1.305316663 1.305341982 1.308200203 1.308903506 1.310115643 1.312387015
## 218 240 410 880 375 437
## 1.313332758 1.315503075 1.315540257 1.319053235 1.320227344 1.320413194
## 644 34 267 590 512 584
## 1.320569903 1.321840173 1.321881620 1.322694885 1.325156697 1.326840927
## 601 901 721 369 480 915
## 1.330759153 1.334348059 1.350872126 1.355569384 1.357511758 1.357758507
## 1 892 145 726 497 900
## 1.359091074 1.363386777 1.367136230 1.372831553 1.388019476 1.388967656
## 702 691 229 907 26 666
## 1.389512896 1.390125767 1.390600443 1.402516762 1.415431148 1.416491137
## 431 699 19 18 700 949
## 1.424477458 1.432987500 1.436898885 1.438009678 1.444526100 1.447423204
## 618 786 95 50 468 848
## 1.449282706 1.456429574 1.456770385 1.457289220 1.460777008 1.471092957
## 690 73 403 188 481 377
## 1.472091467 1.475944337 1.479322985 1.481229119 1.482693481 1.486513421
## 826 898 681 329 680 782
## 1.487037045 1.491237478 1.491991964 1.498583923 1.501801866 1.502022901
## 885 959 163 442 357 291
## 1.522613508 1.523967414 1.526530201 1.528008017 1.533242957 1.533259455
## 184 305 448 106 466 610
## 1.533391735 1.539121826 1.544030581 1.560072493 1.568334702 1.570450890
## 844 59 793 983 540 217
## 1.576056151 1.577905865 1.589065217 1.592509422 1.596081032 1.603585932
## 922 331 401 655 817 633
## 1.619503045 1.622555431 1.622915816 1.625523764 1.627121704 1.635896675
## 827 207 315 100 818 374
## 1.636067374 1.648508327 1.655099980 1.658916632 1.661661296 1.666874835
## 214 131 660 61 250 738
## 1.686725219 1.692412663 1.694211246 1.702310869 1.703885753 1.709284956
## 656 286 736 236 510 117
## 1.710635025 1.711902592 1.713902185 1.722547713 1.726041739 1.729663876
## 197 626 233 966 883 287
## 1.744806780 1.748112654 1.757209650 1.757694823 1.760893592 1.760982819
## 706 504 328 877 102 657
## 1.763148473 1.766934484 1.769913558 1.771439385 1.781423870 1.785028204
## 819 694 143 277 260 288
## 1.785871336 1.786405221 1.791590385 1.798991305 1.823518048 1.825320279
## 244 496 567 257 276 484
## 1.844763669 1.849077780 1.870203834 1.887544666 1.891250492 1.895654910
## 423 594 671 722 528 417
## 1.902075272 1.903568273 1.908008818 1.917638102 1.920291687 1.928817779
## 463 37 960 8 772 419
## 1.949215306 1.957936868 1.959897522 1.975682402 1.997029264 2.003713614
## 837 406 589 70 30 936
## 2.005477415 2.006895522 2.013751790 2.017803195 2.035486148 2.036632138
## 439 974 867 402 758 904
## 2.056898973 2.063336617 2.095521248 2.111848031 2.126128584 2.126189193
## 121 711 301 324 192 134
## 2.129868393 2.135727669 2.135986568 2.136958389 2.141407168 2.141669456
## 543 477 297 38 427 348
## 2.161442621 2.177782363 2.179896078 2.198492713 2.213801642 2.219154487
## 372 63 506 803 317 298
## 2.231785841 2.244778917 2.272656303 2.307248406 2.319415613 2.364442015
## 810 503 133 114 928 814
## 2.369284706 2.383677841 2.435603350 2.452697901 2.540689326 2.542411761
## 472 311 640 208 614 878
## 2.547718438 2.666722085 2.741194054 2.775541990 2.815149073 2.889406727
## 262 780 186 580
## 2.934940420 3.028294758 3.175866638 3.212140482
# Potential outliers - none above 3.29 but 3 cases above 3 which is unlikely to happen by chance!
# 9 cases larger than 2.58 --> 1% of n = 1000 is 10 cases, with 9 cases greater than 2.58 and 12 cases greater than 2.5. This isn't great and suggests that there may be evidence that the level of error within our model is unacceptable;
# 49 cases larger than 1.96 --> 5% of n = 1000 is 50 cases, with 49 cases greater than 1.96. This verges on evidence that the model is a poor representation of the actual data.
#### Assumption of leverage ####
hatvalues(model = model1)
## 1 2 3 4 5 6
## 0.001949013 0.001211976 0.002498738 0.001345188 0.005792782 0.004936732
## 7 8 9 10 11 12
## 0.002946714 0.003949091 0.003723459 0.001003302 0.001346473 0.005278941
## 13 14 15 16 17 18
## 0.001110572 0.003713245 0.004292508 0.001057604 0.004589333 0.001452850
## 19 20 21 22 23 24
## 0.001635021 0.001583697 0.001826815 0.001644564 0.002599521 0.001236273
## 25 26 27 28 29 30
## 0.001342064 0.002698687 0.001420757 0.004304287 0.003249264 0.001553788
## 31 32 33 34 35 36
## 0.002184741 0.001878239 0.006208014 0.003641765 0.001098957 0.006429976
## 37 38 39 40 41 42
## 0.001313905 0.001924041 0.001898173 0.003555514 0.001879309 0.002447606
## 43 44 45 46 47 48
## 0.004285276 0.003104728 0.004098332 0.004518901 0.002708434 0.004016682
## 49 50 51 52 53 54
## 0.001449961 0.010562541 0.004494528 0.003079687 0.010343798 0.001690248
## 55 56 57 58 59 60
## 0.002442994 0.001157181 0.005233388 0.004937928 0.003250594 0.002344773
## 61 62 63 64 65 66
## 0.003160920 0.003045740 0.007092310 0.001624611 0.004840731 0.005055013
## 67 68 69 70 71 72
## 0.002224541 0.001394100 0.001046148 0.002946868 0.003873486 0.001072202
## 73 74 75 76 77 78
## 0.001593248 0.003445935 0.002598737 0.002584051 0.002437759 0.004791944
## 79 80 81 82 83 84
## 0.001695508 0.002684121 0.001792228 0.003182529 0.001100713 0.002134418
## 85 86 87 88 89 90
## 0.002682068 0.001585686 0.007312303 0.003192703 0.008182810 0.002414973
## 91 92 93 94 95 96
## 0.001775578 0.002711845 0.004564911 0.001519945 0.004007351 0.002236606
## 97 98 99 100 101 102
## 0.002360590 0.007158792 0.001870444 0.004195996 0.003326091 0.001913220
## 103 104 105 106 107 108
## 0.002501735 0.001708926 0.001107276 0.004101285 0.004321501 0.001828264
## 109 110 111 112 113 114
## 0.001333941 0.002834999 0.004980116 0.002595966 0.002089087 0.001288932
## 115 116 117 118 119 120
## 0.001127078 0.001164348 0.002384952 0.002014570 0.006457639 0.004104211
## 121 122 123 124 125 126
## 0.003041097 0.001213971 0.001412996 0.001833658 0.001144677 0.001395908
## 127 128 129 130 131 132
## 0.002301841 0.009116553 0.005277989 0.002489838 0.004713894 0.001916067
## 133 134 135 136 137 138
## 0.004364198 0.002859978 0.001972987 0.002858263 0.001422483 0.004324778
## 139 140 141 142 143 144
## 0.002509773 0.008225273 0.002923680 0.001739565 0.004699834 0.004207448
## 145 146 147 148 149 150
## 0.002141640 0.002044812 0.002268490 0.002476729 0.002159158 0.004858454
## 151 152 153 154 155 156
## 0.001524427 0.004541048 0.001414528 0.006536630 0.003886392 0.001278114
## 157 158 159 160 161 162
## 0.001258838 0.001524726 0.001958890 0.001815671 0.003170193 0.001472251
## 163 164 165 166 167 168
## 0.001787689 0.011854487 0.004186216 0.004243100 0.002508867 0.002212670
## 169 170 171 172 173 174
## 0.002678614 0.003086065 0.002015259 0.004610326 0.006971702 0.001561085
## 175 176 177 178 179 180
## 0.001314071 0.002426125 0.001844605 0.002094636 0.002055599 0.001928582
## 181 182 183 184 185 186
## 0.001893051 0.005969399 0.004833474 0.001610609 0.002417813 0.001413122
## 187 188 189 190 191 192
## 0.003774415 0.002121468 0.001291244 0.003795252 0.004369684 0.001530841
## 193 194 195 196 197 198
## 0.003531276 0.007521006 0.001527110 0.006454265 0.008987354 0.002210180
## 199 200 201 202 203 204
## 0.010093075 0.004295835 0.005488943 0.004915864 0.003028678 0.005306781
## 205 206 207 208 209 210
## 0.002971600 0.004770546 0.003955517 0.001282677 0.006264562 0.002349204
## 211 212 213 214 215 216
## 0.002113805 0.002742561 0.004660828 0.001855037 0.003230477 0.005229035
## 217 218 219 220 221 222
## 0.001276726 0.003350405 0.001125157 0.001334014 0.001930860 0.002038887
## 223 224 225 226 227 228
## 0.002100897 0.001799742 0.001304861 0.001063238 0.001134270 0.001578618
## 229 230 231 232 233 234
## 0.001716781 0.003352470 0.005934586 0.007335473 0.001740881 0.001059934
## 235 236 237 238 239 240
## 0.006402137 0.002091462 0.003796763 0.002215977 0.005591492 0.002503934
## 241 242 243 244 245 246
## 0.001484325 0.001382215 0.004438429 0.002424900 0.001883479 0.001241291
## 247 248 249 250 251 252
## 0.005588390 0.002501231 0.003414278 0.003731185 0.001879585 0.004773886
## 253 254 255 256 257 258
## 0.004144794 0.002297516 0.002315228 0.002141862 0.001063379 0.003927440
## 259 260 261 262 263 264
## 0.002379088 0.001396206 0.001459422 0.003590341 0.002863758 0.001283997
## 265 266 267 268 269 270
## 0.001459129 0.001440137 0.001323137 0.002076410 0.002481302 0.003656219
## 271 272 273 274 275 276
## 0.004816727 0.001334357 0.001716781 0.003045167 0.003306641 0.001708157
## 277 278 279 280 281 282
## 0.001165912 0.005208301 0.001139275 0.006014703 0.001689369 0.003636419
## 283 284 285 286 287 288
## 0.003793771 0.002568500 0.003019815 0.002103762 0.001417726 0.001997377
## 289 290 291 292 293 294
## 0.001591233 0.005771001 0.002533036 0.002711294 0.002346235 0.015782265
## 295 296 297 298 299 300
## 0.002500954 0.001507795 0.001688714 0.003204867 0.001351229 0.001593633
## 301 302 303 304 305 306
## 0.004543978 0.003183432 0.004669489 0.002291211 0.003087616 0.001463441
## 307 308 309 310 311 312
## 0.001740125 0.003580756 0.003778582 0.005244111 0.001706510 0.001513003
## 313 314 315 316 317 318
## 0.003708854 0.003217090 0.001726272 0.008394252 0.001259938 0.001220449
## 319 320 321 322 323 324
## 0.001144972 0.002202933 0.007823007 0.001704938 0.001905743 0.005389176
## 325 326 327 328 329 330
## 0.004599578 0.001420906 0.002349359 0.005030823 0.006652478 0.004896597
## 331 332 333 334 335 336
## 0.003544012 0.001086980 0.007879603 0.002784562 0.001945506 0.002086691
## 337 338 339 340 341 342
## 0.006036879 0.002670554 0.002450417 0.004127062 0.001170986 0.001461875
## 343 344 345 346 347 348
## 0.005011918 0.003286973 0.001808460 0.006660024 0.004212251 0.004288362
## 349 350 351 352 353 354
## 0.006853889 0.003828821 0.001310859 0.001006212 0.001150647 0.007817040
## 355 356 357 358 359 360
## 0.001979695 0.004324953 0.001215120 0.001415360 0.001890750 0.001516511
## 361 362 363 364 365 366
## 0.003389505 0.001018429 0.001631691 0.002079365 0.002823994 0.002478292
## 367 368 369 370 371 372
## 0.005411256 0.001389209 0.010787966 0.002905852 0.002007708 0.001994324
## 373 374 375 376 377 378
## 0.001695158 0.002495368 0.001788183 0.001061555 0.007667927 0.001122166
## 379 380 381 382 383 384
## 0.003336972 0.001583042 0.005187248 0.001228880 0.002648470 0.001091074
## 385 386 387 388 389 390
## 0.014512021 0.002907350 0.002241171 0.001796875 0.003302599 0.002413044
## 391 392 393 394 395 396
## 0.001202060 0.001415360 0.005602765 0.001701569 0.007234402 0.001976738
## 397 398 399 400 401 402
## 0.003412777 0.005818541 0.006728325 0.001972432 0.001497133 0.001194621
## 403 404 405 406 407 408
## 0.002011719 0.005756576 0.001169639 0.005051061 0.003580878 0.001233848
## 409 410 411 412 413 414
## 0.002690747 0.002215516 0.006264276 0.001140474 0.003784667 0.003957856
## 415 416 417 418 419 420
## 0.001125189 0.003784296 0.003418150 0.001688585 0.002296505 0.001051713
## 421 422 423 424 425 426
## 0.002720350 0.010299474 0.001596168 0.001721726 0.001142949 0.003218916
## 427 428 429 430 431 432
## 0.001135493 0.001122640 0.001619271 0.001625474 0.002324033 0.001635428
## 433 434 435 436 437 438
## 0.005368078 0.001711990 0.003538199 0.003244425 0.001597955 0.005180599
## 439 440 441 442 443 444
## 0.001018476 0.002009429 0.001090807 0.003352427 0.004294491 0.001868793
## 445 446 447 448 449 450
## 0.002125690 0.001189092 0.001388854 0.001863431 0.001533895 0.001786610
## 451 452 453 454 455 456
## 0.001948123 0.004277322 0.003328472 0.002455333 0.001638789 0.001952035
## 457 458 459 460 461 462
## 0.002899737 0.004064866 0.001388332 0.006043046 0.001635428 0.002241761
## 463 464 465 466 467 468
## 0.001196419 0.002377158 0.004652517 0.003101361 0.004278999 0.007308169
## 469 470 471 472 473 474
## 0.004407998 0.001953712 0.003423594 0.001161550 0.003292279 0.002189320
## 475 476 477 478 479 480
## 0.002016440 0.003714477 0.002209853 0.002145720 0.003144649 0.001540838
## 481 482 483 484 485 486
## 0.002110603 0.001688168 0.005661251 0.001688361 0.002100567 0.005944101
## 487 488 489 490 491 492
## 0.003961405 0.001031693 0.004871905 0.008148627 0.002524440 0.007314487
## 493 494 495 496 497 498
## 0.004388109 0.003069484 0.001578077 0.008519084 0.002631461 0.002415614
## 499 500 501 502 503 504
## 0.004986633 0.004576265 0.001960445 0.001798533 0.001375190 0.001010980
## 505 506 507 508 509 510
## 0.001708517 0.002628140 0.001544393 0.002778874 0.004143750 0.001226393
## 511 512 513 514 515 516
## 0.001477892 0.001166094 0.003468383 0.002632631 0.001608016 0.004012347
## 517 518 519 520 521 522
## 0.001574121 0.003682868 0.001696746 0.003349359 0.001195892 0.001074991
## 523 524 525 526 527 528
## 0.002288500 0.001984255 0.001381741 0.001611413 0.001989780 0.003593636
## 529 530 531 532 533 534
## 0.003526578 0.003882384 0.001275165 0.001072287 0.002433547 0.001493699
## 535 536 537 538 539 540
## 0.001598623 0.004857290 0.002805751 0.001935011 0.002266781 0.003328472
## 541 542 543 544 545 546
## 0.001249075 0.001045440 0.001900697 0.002009670 0.001653522 0.005478944
## 547 548 549 550 551 552
## 0.001646630 0.001700904 0.001304745 0.004446102 0.001844511 0.001583697
## 553 554 555 556 557 558
## 0.002729277 0.001578147 0.004589333 0.001525817 0.002841695 0.001309014
## 559 560 561 562 563 564
## 0.001199884 0.001576500 0.002094466 0.001198628 0.001545755 0.001850638
## 565 566 567 568 569 570
## 0.002151822 0.002427558 0.004728500 0.002127915 0.003627936 0.001043172
## 571 572 573 574 575 576
## 0.001062502 0.003266763 0.002270076 0.009466889 0.001076590 0.002102083
## 577 578 579 580 581 582
## 0.002519612 0.008816840 0.002127946 0.005368073 0.002892308 0.009709381
## 583 584 585 586 587 588
## 0.002021895 0.002681886 0.001163264 0.003509723 0.007459114 0.003827040
## 589 590 591 592 593 594
## 0.005093655 0.001091977 0.010091188 0.001889735 0.004978752 0.002244811
## 595 596 597 598 599 600
## 0.001686675 0.002624737 0.001293160 0.002261866 0.001997297 0.002636867
## 601 602 603 604 605 606
## 0.001556892 0.004530448 0.004213209 0.004048931 0.002624737 0.001012723
## 607 608 609 610 611 612
## 0.004349449 0.001017083 0.002208520 0.005487976 0.001875046 0.001685720
## 613 614 615 616 617 618
## 0.001958450 0.001123548 0.003564019 0.001294427 0.005562007 0.002299510
## 619 620 621 622 623 624
## 0.001734780 0.001775808 0.001083913 0.002496605 0.004295089 0.003568972
## 625 626 627 628 629 630
## 0.007528470 0.002966049 0.003170554 0.001306820 0.003535213 0.001620215
## 631 632 633 634 635 636
## 0.003473191 0.001508736 0.003379237 0.001457109 0.001810815 0.009710783
## 637 638 639 640 641 642
## 0.004426400 0.003680115 0.001061243 0.003038712 0.001426419 0.008730864
## 643 644 645 646 647 648
## 0.001909928 0.003606585 0.002961732 0.004099789 0.004452140 0.002289860
## 649 650 651 652 653 654
## 0.003445330 0.001855539 0.001973908 0.003880898 0.001836099 0.004338154
## 655 656 657 658 659 660
## 0.002324033 0.003030043 0.001102412 0.004005521 0.001568246 0.001928285
## 661 662 663 664 665 666
## 0.001217688 0.001394100 0.001371448 0.003742430 0.001357585 0.002751654
## 667 668 669 670 671 672
## 0.001787854 0.003768615 0.003385367 0.003174524 0.003057778 0.001236645
## 673 674 675 676 677 678
## 0.003557688 0.002101372 0.005613366 0.001588597 0.002512582 0.001690110
## 679 680 681 682 683 684
## 0.001349611 0.001491006 0.001633995 0.005687905 0.003822088 0.002747944
## 685 686 687 688 689 690
## 0.001832789 0.004269532 0.008258620 0.003358433 0.001771262 0.005629434
## 691 692 693 694 695 696
## 0.001800348 0.001476588 0.001057210 0.006849787 0.006031307 0.001073090
## 697 698 699 700 701 702
## 0.005037279 0.003480544 0.005170373 0.002672464 0.003293060 0.001151162
## 703 704 705 706 707 708
## 0.005705865 0.004412148 0.007210195 0.003864918 0.002291211 0.001132578
## 709 710 711 712 713 714
## 0.002300889 0.002001884 0.003332781 0.001126230 0.003516417 0.004272073
## 715 716 717 718 719 720
## 0.002733865 0.001708157 0.002052061 0.001966580 0.003979170 0.003063106
## 721 722 723 724 725 726
## 0.001156238 0.002372423 0.003087357 0.002021808 0.003743142 0.003573979
## 727 728 729 730 731 732
## 0.003926389 0.004707863 0.001359868 0.001367816 0.001893072 0.004007212
## 733 734 735 736 737 738
## 0.001666802 0.006228698 0.001364596 0.006331195 0.001857146 0.004823928
## 739 740 741 742 743 744
## 0.001945109 0.009675678 0.001299789 0.006681554 0.001481570 0.002881650
## 745 746 747 748 749 750
## 0.002609602 0.003712556 0.002462294 0.002387401 0.003347339 0.001185219
## 751 752 753 754 755 756
## 0.003935532 0.001288743 0.008729852 0.004387675 0.002199916 0.002965117
## 757 758 759 760 761 762
## 0.008074595 0.003758983 0.002309321 0.005075633 0.003090734 0.002578611
## 763 764 765 766 767 768
## 0.004635963 0.001811489 0.002492879 0.006334088 0.001036675 0.001269882
## 769 770 771 772 773 774
## 0.006740976 0.002423154 0.001988847 0.002122903 0.001310978 0.002709603
## 775 776 777 778 779 780
## 0.003853128 0.004855198 0.001199595 0.005501743 0.002291430 0.003623402
## 781 782 783 784 785 786
## 0.001164452 0.001021385 0.002405104 0.002752317 0.002044658 0.001892906
## 787 788 789 790 791 792
## 0.001585006 0.005849353 0.002132349 0.002272656 0.004966384 0.002228699
## 793 794 795 796 797 798
## 0.003001688 0.009028940 0.008348126 0.001126392 0.005227795 0.001726950
## 799 800 801 802 803 804
## 0.006545059 0.002880571 0.001184598 0.004056940 0.001035687 0.001271132
## 805 806 807 808 809 810
## 0.001883479 0.001586850 0.001050337 0.004283816 0.003763651 0.001226776
## 811 812 813 814 815 816
## 0.001788940 0.003668921 0.003352043 0.001075122 0.001782087 0.004630349
## 817 818 819 820 821 822
## 0.001704704 0.001209267 0.002312239 0.001994673 0.003692513 0.003596397
## 823 824 825 826 827 828
## 0.001215146 0.001695083 0.001223805 0.002670346 0.004680481 0.002147271
## 829 830 831 832 833 834
## 0.001219286 0.001596558 0.005307434 0.002620048 0.004100816 0.002631149
## 835 836 837 838 839 840
## 0.001423151 0.002075040 0.003233032 0.001802816 0.003405637 0.001221913
## 841 842 843 844 845 846
## 0.003811022 0.003666791 0.004641274 0.005811042 0.001271265 0.003930060
## 847 848 849 850 851 852
## 0.001342286 0.004348178 0.001362671 0.001096102 0.002850883 0.001007799
## 853 854 855 856 857 858
## 0.001452053 0.001219491 0.004680096 0.001797391 0.005345888 0.007445266
## 859 860 861 862 863 864
## 0.004166477 0.001006507 0.001192957 0.005083749 0.007384192 0.002108325
## 865 866 867 868 869 870
## 0.003898196 0.003351752 0.001897378 0.002123567 0.002055240 0.004055204
## 871 872 873 874 875 876
## 0.002779816 0.001694839 0.003175588 0.002850373 0.002778530 0.001279304
## 877 878 879 880 881 882
## 0.002296271 0.002489795 0.002263474 0.001580165 0.004409092 0.003199298
## 883 884 885 886 887 888
## 0.002949657 0.009281806 0.001832181 0.003759712 0.005233403 0.001241963
## 889 890 891 892 893 894
## 0.006879841 0.001832872 0.004016638 0.002628893 0.002736725 0.001394346
## 895 896 897 898 899 900
## 0.005535301 0.004135535 0.006100275 0.001443719 0.001873336 0.003111848
## 901 902 903 904 905 906
## 0.004631287 0.001879922 0.006166784 0.001112752 0.002587800 0.001318875
## 907 908 909 910 911 912
## 0.001381234 0.004875096 0.001062122 0.003207207 0.001137717 0.001021469
## 913 914 915 916 917 918
## 0.001176556 0.002593173 0.003350114 0.002086799 0.003011056 0.002124603
## 919 920 921 922 923 924
## 0.005540082 0.001382518 0.001111301 0.002466670 0.004527149 0.002366757
## 925 926 927 928 929 930
## 0.001996145 0.001592296 0.001101991 0.001073558 0.001719458 0.001921859
## 931 932 933 934 935 936
## 0.003525883 0.004879165 0.004997834 0.001024762 0.003454083 0.005098350
## 937 938 939 940 941 942
## 0.001896704 0.006620957 0.001095061 0.001351118 0.002997479 0.002218254
## 943 944 945 946 947 948
## 0.002795784 0.003149821 0.002431264 0.002844803 0.002870554 0.002138113
## 949 950 951 952 953 954
## 0.002117136 0.002807795 0.001339643 0.001902897 0.002215342 0.005730955
## 955 956 957 958 959 960
## 0.002520227 0.001112943 0.001456401 0.001608471 0.003276222 0.001753702
## 961 962 963 964 965 966
## 0.004358482 0.003734293 0.002247755 0.003818618 0.002021466 0.001367352
## 967 968 969 970 971 972
## 0.002193227 0.003336972 0.001070312 0.001992822 0.007146518 0.001098957
## 973 974 975 976 977 978
## 0.006027391 0.003178316 0.002183133 0.001321481 0.002814418 0.003635124
## 979 980 981 982 983 984
## 0.001665803 0.002255489 0.002625877 0.010769351 0.001325526 0.005363353
## 985 986 987 988 989 990
## 0.002589987 0.002733231 0.001291042 0.001059675 0.001458497 0.004800558
## 991 992 993 994 995 996
## 0.001538816 0.001035312 0.001035493 0.001104109 0.003190925 0.003226719
## 997 998 999 1000
## 0.002337343 0.003821235 0.002633922 0.001665501
mean(hatvalues(model1)) # mean = 0.003
## [1] 0.003
sort(hatvalues(model1))
## 10 352 860 852 504 606
## 0.001003302 0.001006212 0.001006507 0.001007799 0.001010980 0.001012723
## 608 362 439 782 912 934
## 0.001017083 0.001018429 0.001018476 0.001021385 0.001021469 0.001024762
## 488 992 993 803 767 570
## 0.001031693 0.001035312 0.001035493 0.001035687 0.001036675 0.001043172
## 542 69 807 420 693 16
## 0.001045440 0.001046148 0.001050337 0.001051713 0.001057210 0.001057604
## 988 234 639 376 909 571
## 0.001059675 0.001059934 0.001061243 0.001061555 0.001062122 0.001062502
## 226 257 969 72 532 696
## 0.001063238 0.001063379 0.001070312 0.001072202 0.001072287 0.001073090
## 928 522 814 575 621 332
## 0.001073558 0.001074991 0.001075122 0.001076590 0.001083913 0.001086980
## 441 384 590 939 850 35
## 0.001090807 0.001091074 0.001091977 0.001095061 0.001096102 0.001098957
## 972 83 927 657 994 105
## 0.001098957 0.001100713 0.001101991 0.001102412 0.001104109 0.001107276
## 13 921 904 956 378 428
## 0.001110572 0.001111301 0.001112752 0.001112943 0.001122166 0.001122640
## 614 219 415 712 796 115
## 0.001123548 0.001125157 0.001125189 0.001126230 0.001126392 0.001127078
## 708 227 427 911 279 412
## 0.001132578 0.001134270 0.001135493 0.001137717 0.001139275 0.001140474
## 425 125 319 353 702 721
## 0.001142949 0.001144677 0.001144972 0.001150647 0.001151162 0.001156238
## 56 472 585 116 781 277
## 0.001157181 0.001161550 0.001163264 0.001164348 0.001164452 0.001165912
## 512 405 341 913 801 750
## 0.001166094 0.001169639 0.001170986 0.001176556 0.001184598 0.001185219
## 446 861 402 521 463 562
## 0.001189092 0.001192957 0.001194621 0.001195892 0.001196419 0.001198628
## 777 559 391 818 2 122
## 0.001199595 0.001199884 0.001202060 0.001209267 0.001211976 0.001213971
## 357 823 661 829 854 318
## 0.001215120 0.001215146 0.001217688 0.001219286 0.001219491 0.001220449
## 840 825 510 810 382 408
## 0.001221913 0.001223805 0.001226393 0.001226776 0.001228880 0.001233848
## 24 672 246 888 541 157
## 0.001236273 0.001236645 0.001241291 0.001241963 0.001249075 0.001258838
## 317 768 804 845 531 217
## 0.001259938 0.001269882 0.001271132 0.001271265 0.001275165 0.001276726
## 156 876 208 264 752 114
## 0.001278114 0.001279304 0.001282677 0.001283997 0.001288743 0.001288932
## 987 189 597 616 741 549
## 0.001291042 0.001291244 0.001293160 0.001294427 0.001299789 0.001304745
## 225 628 558 351 773 37
## 0.001304861 0.001306820 0.001309014 0.001310859 0.001310978 0.001313905
## 175 906 976 267 983 109
## 0.001314071 0.001318875 0.001321481 0.001323137 0.001325526 0.001333941
## 220 272 951 25 847 4
## 0.001334014 0.001334357 0.001339643 0.001342064 0.001342286 0.001345188
## 11 679 940 299 665 729
## 0.001346473 0.001349611 0.001351118 0.001351229 0.001357585 0.001359868
## 849 735 966 730 663 503
## 0.001362671 0.001364596 0.001367352 0.001367816 0.001371448 0.001375190
## 907 525 242 920 459 447
## 0.001381234 0.001381741 0.001382215 0.001382518 0.001388332 0.001388854
## 368 68 662 894 126 260
## 0.001389209 0.001394100 0.001394100 0.001394346 0.001395908 0.001396206
## 123 186 153 358 392 287
## 0.001412996 0.001413122 0.001414528 0.001415360 0.001415360 0.001417726
## 27 326 137 835 641 266
## 0.001420757 0.001420906 0.001422483 0.001423151 0.001426419 0.001440137
## 898 49 853 18 957 634
## 0.001443719 0.001449961 0.001452053 0.001452850 0.001456401 0.001457109
## 989 265 261 342 306 162
## 0.001458497 0.001459129 0.001459422 0.001461875 0.001463441 0.001472251
## 692 511 743 241 680 534
## 0.001476588 0.001477892 0.001481570 0.001484325 0.001491006 0.001493699
## 401 296 632 312 360 94
## 0.001497133 0.001507795 0.001508736 0.001513003 0.001516511 0.001519945
## 151 158 556 195 192 449
## 0.001524427 0.001524726 0.001525817 0.001527110 0.001530841 0.001533895
## 991 480 507 563 30 601
## 0.001538816 0.001540838 0.001544393 0.001545755 0.001553788 0.001556892
## 174 659 517 560 495 554
## 0.001561085 0.001568246 0.001574121 0.001576500 0.001578077 0.001578147
## 228 880 380 20 552 787
## 0.001578618 0.001580165 0.001583042 0.001583697 0.001583697 0.001585006
## 86 806 676 289 926 73
## 0.001585686 0.001586850 0.001588597 0.001591233 0.001592296 0.001593248
## 300 423 830 437 535 515
## 0.001593633 0.001596168 0.001596558 0.001597955 0.001598623 0.001608016
## 958 184 526 429 630 64
## 0.001608471 0.001610609 0.001611413 0.001619271 0.001620215 0.001624611
## 430 363 681 19 432 461
## 0.001625474 0.001631691 0.001633995 0.001635021 0.001635428 0.001635428
## 455 22 547 545 1000 979
## 0.001638789 0.001644564 0.001646630 0.001653522 0.001665501 0.001665803
## 733 612 595 482 484 418
## 0.001666802 0.001685720 0.001686675 0.001688168 0.001688361 0.001688585
## 297 281 678 54 872 824
## 0.001688714 0.001689369 0.001690110 0.001690248 0.001694839 0.001695083
## 373 79 519 548 394 817
## 0.001695158 0.001695508 0.001696746 0.001700904 0.001701569 0.001704704
## 322 311 276 716 505 104
## 0.001704938 0.001706510 0.001708157 0.001708157 0.001708517 0.001708926
## 434 229 273 929 424 315
## 0.001711990 0.001716781 0.001716781 0.001719458 0.001721726 0.001726272
## 798 619 142 307 233 960
## 0.001726950 0.001734780 0.001739565 0.001740125 0.001740881 0.001753702
## 689 91 620 815 450 163
## 0.001771262 0.001775578 0.001775808 0.001782087 0.001786610 0.001787689
## 667 375 811 81 388 856
## 0.001787854 0.001788183 0.001788940 0.001792228 0.001796875 0.001797391
## 502 224 691 838 345 635
## 0.001798533 0.001799742 0.001800348 0.001802816 0.001808460 0.001810815
## 764 160 21 108 885 685
## 0.001811489 0.001815671 0.001826815 0.001828264 0.001832181 0.001832789
## 890 124 653 551 177 564
## 0.001832872 0.001833658 0.001836099 0.001844511 0.001844605 0.001850638
## 214 650 737 448 444 99
## 0.001855037 0.001855539 0.001857146 0.001863431 0.001868793 0.001870444
## 899 611 32 41 251 902
## 0.001873336 0.001875046 0.001878239 0.001879309 0.001879585 0.001879922
## 245 805 592 359 786 181
## 0.001883479 0.001883479 0.001889735 0.001890750 0.001892906 0.001893051
## 731 937 867 39 543 952
## 0.001893072 0.001896704 0.001897378 0.001898173 0.001900697 0.001902897
## 323 643 102 132 930 38
## 0.001905743 0.001909928 0.001913220 0.001916067 0.001921859 0.001924041
## 660 180 221 538 739 335
## 0.001928285 0.001928582 0.001930860 0.001935011 0.001945109 0.001945506
## 451 1 456 470 613 159
## 0.001948123 0.001949013 0.001952035 0.001953712 0.001958450 0.001958890
## 501 718 400 135 651 396
## 0.001960445 0.001966580 0.001972432 0.001972987 0.001973908 0.001976738
## 355 524 771 527 970 372
## 0.001979695 0.001984255 0.001988847 0.001989780 0.001992822 0.001994324
## 820 925 599 288 710 371
## 0.001994673 0.001996145 0.001997297 0.001997377 0.002001884 0.002007708
## 440 544 403 118 171 475
## 0.002009429 0.002009670 0.002011719 0.002014570 0.002015259 0.002016440
## 965 724 583 222 785 146
## 0.002021466 0.002021808 0.002021895 0.002038887 0.002044658 0.002044812
## 717 869 179 836 268 364
## 0.002052061 0.002055240 0.002055599 0.002075040 0.002076410 0.002079365
## 336 916 113 236 561 178
## 0.002086691 0.002086799 0.002089087 0.002091462 0.002094466 0.002094636
## 485 223 674 576 286 864
## 0.002100567 0.002100897 0.002101372 0.002102083 0.002103762 0.002108325
## 481 211 949 188 772 868
## 0.002110603 0.002113805 0.002117136 0.002121468 0.002122903 0.002123567
## 918 445 568 579 789 84
## 0.002124603 0.002125690 0.002127915 0.002127946 0.002132349 0.002134418
## 948 145 256 478 828 565
## 0.002138113 0.002141640 0.002141862 0.002145720 0.002147271 0.002151822
## 149 975 31 474 967 755
## 0.002159158 0.002183133 0.002184741 0.002189320 0.002193227 0.002199916
## 320 609 477 198 168 953
## 0.002202933 0.002208520 0.002209853 0.002210180 0.002212670 0.002215342
## 410 238 942 67 792 96
## 0.002215516 0.002215977 0.002218254 0.002224541 0.002228699 0.002236606
## 387 462 594 963 980 598
## 0.002241171 0.002241761 0.002244811 0.002247755 0.002255489 0.002261866
## 879 539 147 573 790 523
## 0.002263474 0.002266781 0.002268490 0.002270076 0.002272656 0.002288500
## 648 304 707 779 877 419
## 0.002289860 0.002291211 0.002291211 0.002291430 0.002296271 0.002296505
## 254 618 709 127 759 819
## 0.002297516 0.002299510 0.002300889 0.002301841 0.002309321 0.002312239
## 255 431 655 997 60 293
## 0.002315228 0.002324033 0.002324033 0.002337343 0.002344773 0.002346235
## 210 327 97 924 722 464
## 0.002349204 0.002349359 0.002360590 0.002366757 0.002372423 0.002377158
## 259 117 748 783 390 90
## 0.002379088 0.002384952 0.002387401 0.002405104 0.002413044 0.002414973
## 498 185 770 244 176 566
## 0.002415614 0.002417813 0.002423154 0.002424900 0.002426125 0.002427558
## 945 533 77 55 42 339
## 0.002431264 0.002433547 0.002437759 0.002442994 0.002447606 0.002450417
## 454 747 922 148 366 269
## 0.002455333 0.002462294 0.002466670 0.002476729 0.002478292 0.002481302
## 878 130 765 374 622 3
## 0.002489795 0.002489838 0.002492879 0.002495368 0.002496605 0.002498738
## 295 248 103 240 167 139
## 0.002500954 0.002501231 0.002501735 0.002503934 0.002508867 0.002509773
## 677 577 955 491 291 284
## 0.002512582 0.002519612 0.002520227 0.002524440 0.002533036 0.002568500
## 762 76 905 985 914 112
## 0.002578611 0.002584051 0.002587800 0.002589987 0.002593173 0.002595966
## 75 23 745 832 596 605
## 0.002598737 0.002599521 0.002609602 0.002620048 0.002624737 0.002624737
## 981 506 892 834 497 514
## 0.002625877 0.002628140 0.002628893 0.002631149 0.002631461 0.002632631
## 999 600 383 826 338 700
## 0.002633922 0.002636867 0.002648470 0.002670346 0.002670554 0.002672464
## 169 584 85 80 409 26
## 0.002678614 0.002681886 0.002682068 0.002684121 0.002690747 0.002698687
## 47 774 292 92 421 553
## 0.002708434 0.002709603 0.002711294 0.002711845 0.002720350 0.002729277
## 986 715 893 212 684 666
## 0.002733231 0.002733865 0.002736725 0.002742561 0.002747944 0.002751654
## 784 875 508 871 334 943
## 0.002752317 0.002778530 0.002778874 0.002779816 0.002784562 0.002795784
## 537 950 977 365 110 557
## 0.002805751 0.002807795 0.002814418 0.002823994 0.002834999 0.002841695
## 946 874 851 136 134 263
## 0.002844803 0.002850373 0.002850883 0.002858263 0.002859978 0.002863758
## 947 800 744 581 457 370
## 0.002870554 0.002880571 0.002881650 0.002892308 0.002899737 0.002905852
## 386 141 7 70 883 645
## 0.002907350 0.002923680 0.002946714 0.002946868 0.002949657 0.002961732
## 756 626 205 941 793 917
## 0.002965117 0.002966049 0.002971600 0.002997479 0.003001688 0.003011056
## 285 203 656 640 121 274
## 0.003019815 0.003028678 0.003030043 0.003038712 0.003041097 0.003045167
## 62 671 720 494 52 170
## 0.003045740 0.003057778 0.003063106 0.003069484 0.003079687 0.003086065
## 723 305 761 466 44 900
## 0.003087357 0.003087616 0.003090734 0.003101361 0.003104728 0.003111848
## 479 944 61 161 627 670
## 0.003144649 0.003149821 0.003160920 0.003170193 0.003170554 0.003174524
## 873 974 82 302 995 88
## 0.003175588 0.003178316 0.003182529 0.003183432 0.003190925 0.003192703
## 882 298 910 314 426 996
## 0.003199298 0.003204867 0.003207207 0.003217090 0.003218916 0.003226719
## 215 837 436 29 59 572
## 0.003230477 0.003233032 0.003244425 0.003249264 0.003250594 0.003266763
## 959 344 473 701 389 275
## 0.003276222 0.003286973 0.003292279 0.003293060 0.003302599 0.003306641
## 101 453 540 711 379 968
## 0.003326091 0.003328472 0.003328472 0.003332781 0.003336972 0.003336972
## 749 520 915 218 866 813
## 0.003347339 0.003349359 0.003350114 0.003350405 0.003351752 0.003352043
## 442 230 688 633 669 361
## 0.003352427 0.003352470 0.003358433 0.003379237 0.003385367 0.003389505
## 839 397 249 417 471 649
## 0.003405637 0.003412777 0.003414278 0.003418150 0.003423594 0.003445330
## 74 935 513 631 698 586
## 0.003445935 0.003454083 0.003468383 0.003473191 0.003480544 0.003509723
## 713 931 529 193 629 435
## 0.003516417 0.003525883 0.003526578 0.003531276 0.003535213 0.003538199
## 331 40 673 615 624 726
## 0.003544012 0.003555514 0.003557688 0.003564019 0.003568972 0.003573979
## 308 407 262 528 822 644
## 0.003580756 0.003580878 0.003590341 0.003593636 0.003596397 0.003606585
## 780 569 978 282 34 270
## 0.003623402 0.003627936 0.003635124 0.003636419 0.003641765 0.003656219
## 842 812 638 518 821 313
## 0.003666791 0.003668921 0.003680115 0.003682868 0.003692513 0.003708854
## 746 14 476 9 250 962
## 0.003712556 0.003713245 0.003714477 0.003723459 0.003731185 0.003734293
## 664 725 758 886 809 668
## 0.003742430 0.003743142 0.003758983 0.003759712 0.003763651 0.003768615
## 187 309 416 413 283 190
## 0.003774415 0.003778582 0.003784296 0.003784667 0.003793771 0.003795252
## 237 841 964 998 683 588
## 0.003796763 0.003811022 0.003818618 0.003821235 0.003822088 0.003827040
## 350 775 706 71 652 530
## 0.003828821 0.003853128 0.003864918 0.003873486 0.003880898 0.003882384
## 155 865 727 258 846 751
## 0.003886392 0.003898196 0.003926389 0.003927440 0.003930060 0.003935532
## 8 207 414 487 719 658
## 0.003949091 0.003955517 0.003957856 0.003961405 0.003979170 0.004005521
## 732 95 516 891 48 604
## 0.004007212 0.004007351 0.004012347 0.004016638 0.004016682 0.004048931
## 870 802 458 45 646 833
## 0.004055204 0.004056940 0.004064866 0.004098332 0.004099789 0.004100816
## 106 120 340 896 509 253
## 0.004101285 0.004104211 0.004127062 0.004135535 0.004143750 0.004144794
## 859 165 100 144 347 603
## 0.004166477 0.004186216 0.004195996 0.004207448 0.004212251 0.004213209
## 166 686 714 452 467 808
## 0.004243100 0.004269532 0.004272073 0.004277322 0.004278999 0.004283816
## 43 348 15 443 623 200
## 0.004285276 0.004288362 0.004292508 0.004294491 0.004295089 0.004295835
## 28 107 138 356 654 848
## 0.004304287 0.004321501 0.004324778 0.004324953 0.004338154 0.004348178
## 607 961 133 191 754 493
## 0.004349449 0.004358482 0.004364198 0.004369684 0.004387675 0.004388109
## 469 881 704 637 243 550
## 0.004407998 0.004409092 0.004412148 0.004426400 0.004438429 0.004446102
## 647 51 46 923 602 152
## 0.004452140 0.004494528 0.004518901 0.004527149 0.004530448 0.004541048
## 301 93 500 17 555 325
## 0.004543978 0.004564911 0.004576265 0.004589333 0.004589333 0.004599578
## 172 816 901 763 843 465
## 0.004610326 0.004630349 0.004631287 0.004635963 0.004641274 0.004652517
## 213 303 855 827 143 728
## 0.004660828 0.004669489 0.004680096 0.004680481 0.004699834 0.004707863
## 131 567 206 252 78 990
## 0.004713894 0.004728500 0.004770546 0.004773886 0.004791944 0.004800558
## 271 738 183 65 776 536
## 0.004816727 0.004823928 0.004833474 0.004840731 0.004855198 0.004857290
## 150 489 908 932 330 202
## 0.004858454 0.004871905 0.004875096 0.004879165 0.004896597 0.004915864
## 6 58 791 593 111 499
## 0.004936732 0.004937928 0.004966384 0.004978752 0.004980116 0.004986633
## 933 343 328 697 406 66
## 0.004997834 0.005011918 0.005030823 0.005037279 0.005051061 0.005055013
## 760 862 589 936 699 438
## 0.005075633 0.005083749 0.005093655 0.005098350 0.005170373 0.005180599
## 381 278 797 216 57 887
## 0.005187248 0.005208301 0.005227795 0.005229035 0.005233388 0.005233403
## 310 129 12 204 831 857
## 0.005244111 0.005277989 0.005278941 0.005306781 0.005307434 0.005345888
## 984 580 433 324 367 546
## 0.005363353 0.005368073 0.005368078 0.005389176 0.005411256 0.005478944
## 610 201 778 895 919 617
## 0.005487976 0.005488943 0.005501743 0.005535301 0.005540082 0.005562007
## 247 239 393 675 690 483
## 0.005588390 0.005591492 0.005602765 0.005613366 0.005629434 0.005661251
## 682 703 954 404 290 5
## 0.005687905 0.005705865 0.005730955 0.005756576 0.005771001 0.005792782
## 844 398 788 231 486 182
## 0.005811042 0.005818541 0.005849353 0.005934586 0.005944101 0.005969399
## 280 973 695 337 460 897
## 0.006014703 0.006027391 0.006031307 0.006036879 0.006043046 0.006100275
## 903 33 734 411 209 736
## 0.006166784 0.006208014 0.006228698 0.006264276 0.006264562 0.006331195
## 766 235 36 196 119 154
## 0.006334088 0.006402137 0.006429976 0.006454265 0.006457639 0.006536630
## 799 938 329 346 742 399
## 0.006545059 0.006620957 0.006652478 0.006660024 0.006681554 0.006728325
## 769 694 349 889 173 63
## 0.006740976 0.006849787 0.006853889 0.006879841 0.006971702 0.007092310
## 971 98 705 395 468 87
## 0.007146518 0.007158792 0.007210195 0.007234402 0.007308169 0.007312303
## 492 232 863 858 587 194
## 0.007314487 0.007335473 0.007384192 0.007445266 0.007459114 0.007521006
## 625 377 354 321 333 757
## 0.007528470 0.007667927 0.007817040 0.007823007 0.007879603 0.008074595
## 490 89 140 687 795 316
## 0.008148627 0.008182810 0.008225273 0.008258620 0.008348126 0.008394252
## 496 753 642 578 197 794
## 0.008519084 0.008729852 0.008730864 0.008816840 0.008987354 0.009028940
## 128 884 574 740 582 636
## 0.009116553 0.009281806 0.009466889 0.009675678 0.009709381 0.009710783
## 591 199 422 53 50 982
## 0.010091188 0.010093075 0.010299474 0.010343798 0.010562541 0.010769351
## 369 164 385 294
## 0.010787966 0.011854487 0.014512021 0.015782265
summary(hatvalues(model1)) # Given n = 1000, range of hat values is reasonable (0.001003 to 0.015782)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.001003 0.001598 0.002386 0.003000 0.003827 0.015782
# Step 1: Obtain the sum of hat values
hat_values <- hatvalues(model1)
sum_hat_values <- sum(hat_values)
# Step 2: Calculate the ratio of predictors to sample size
k <- length(coefficients(model1)) - 1 # Number of predictors excluding the intercept
n <- length(residuals(model1)) # Sample size
ratio_k_n <- k / n
# Compare the sum of hat values to the ratio of k/n
if (sum_hat_values > ratio_k_n) {
cat("The sum of hat values is higher than the ratio of predictors to sample size.\n")
} else {
cat("The sum of hat values is within acceptable limits relative to the ratio of predictors to sample size.\n")
} # some concern here given that results show he sum of hat values is higher than the ratio of predictors to sample size.
## The sum of hat values is higher than the ratio of predictors to sample size.
# Plot model1
plot(model1, which = 4) # cook's distance
plot(model1, which = 5) # residuals vs. leverage
# Outliers flagged 63, 580, 780
# Delete specific items
del1<-(c(63,580,780))
model_del <-lm(GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat, na.action = na.exclude, subset=-del1)
summary(model_del) # Significant model: F(2,994) = 171.3, R-sq = .26, p<.001
##
## Call:
## lm(formula = GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat,
## subset = -del1, na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.27212 -0.30181 0.01378 0.30445 1.38829
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.384e+00 1.640e-01 14.534 <2e-16 ***
## Ability_Tot 9.251e-04 5.035e-05 18.373 <2e-16 ***
## Motivate_Tot 2.330e-03 1.473e-03 1.582 0.114
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4318 on 994 degrees of freedom
## Multiple R-squared: 0.2563, Adjusted R-squared: 0.2548
## F-statistic: 171.3 on 2 and 994 DF, p-value: < 2.2e-16
plot(model_del)
confint(model_del)
## 2.5 % 97.5 %
## (Intercept) 2.0623708571 2.706201642
## Ability_Tot 0.0008263260 0.001023950
## Motivate_Tot -0.0005607222 0.005221208
#### 1. D. Multiple regression predicting GPA from Ability and Motivate composites ####
model1 <-lm(GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat, na.action = na.exclude)
summary(model1) # Significant model: F(2,97) = 161.6, R-sq = .24, p<.001
##
## Call:
## lm(formula = GPA ~ Ability_Tot + Motivate_Tot, data = clean.dat,
## na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.31967 -0.31147 0.01266 0.30473 1.39856
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.4395853 0.1653663 14.753 <2e-16 ***
## Ability_Tot 0.0009058 0.0000507 17.864 <2e-16 ***
## Motivate_Tot 0.0020591 0.0014857 1.386 0.166
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4366 on 997 degrees of freedom
## Multiple R-squared: 0.2448, Adjusted R-squared: 0.2433
## F-statistic: 161.6 on 2 and 997 DF, p-value: < 2.2e-16
plot(model1)
confint(model1) # CI for Ability_Tot and Motivate_Tot include 0, model CI [2.115, 2.764]
## 2.5 % 97.5 %
## (Intercept) 2.1150792603 2.764091275
## Ability_Tot 0.0008062660 0.001005263
## Motivate_Tot -0.0008564176 0.004974662
#### 1. E. Multiple regression predicting GPA from GREV, GREQ, GREA, Ach, and Anx ####
model2 <-lm(GPA ~ GREV + GREQ + GREA + Ach + Anx, data = clean.dat, na.action = na.exclude)
summary(model2) # Significant model: F(2,97) = 161.6, R-sq = .24, p<.001
##
## Call:
## lm(formula = GPA ~ GREV + GREQ + GREA + Ach + Anx, data = clean.dat,
## na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.3069 -0.3080 0.0112 0.3032 1.2733
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.5150625 0.1608958 15.632 < 2e-16 ***
## GREV 0.0009396 0.0002090 4.497 7.72e-06 ***
## GREQ 0.0002464 0.0001982 1.243 0.214094
## GREA 0.0014297 0.0002352 6.078 1.73e-09 ***
## Ach 0.0060682 0.0018198 3.334 0.000886 ***
## Anx -0.0023829 0.0017023 -1.400 0.161883
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.423 on 994 degrees of freedom
## Multiple R-squared: 0.2931, Adjusted R-squared: 0.2895
## F-statistic: 82.43 on 5 and 994 DF, p-value: < 2.2e-16
plot(model2)
confint(model2)
## 2.5 % 97.5 %
## (Intercept) 2.1993279909 2.8307969602
## GREV 0.0005295462 0.0013496480
## GREQ -0.0001425267 0.0006352777
## GREA 0.0009681532 0.0018912927
## Ach 0.0024970258 0.0096393787
## Anx -0.0057233228 0.0009576060
##### 1. F. Center variables ####
clean.dat <- clean.dat %>%
mutate(
C_GREV = (GREV - (mean(clean.dat$GREV))),
C_GREQ = (GREQ - (mean(clean.dat$GREQ))),
C_GREA = (GREA - (mean(clean.dat$GREA))),
C_Ach = (Ach - (mean(clean.dat$Ach))),
C_Anx = (Anx - (mean(clean.dat$Anx)))
)
#### Multiple regression predicting typical GPA from average scores on GREV, GREQ, GREA, Ach, and Anx ####
C_model <-lm(GPA ~ C_GREV + C_GREQ + C_GREA + C_Ach + C_Anx, data = clean.dat, na.action = na.exclude)
#summary(C_model) # Significant model: F(2,97) = 161.6, R-sq = .24, p<.001
#plot(C_model)
#confint(C_model) # CI for Ability_Tot and Motivate_Tot include 0, model CI [2.115, 2.764]
#### PROCESS for R version 4.2 beta ####
# Written by Andrew F. Hayes
# www.afhayes.com
# www.processmacro.org
# Copyright 2012-2022 by Andrew F. Hayes ALL RIGHTS RESERVED
# Documented in http://www.guilford.com/p/hayes3 and supplements
# PROCESS workshop schedule at http://haskayne.ucalgary.ca/CCRAM
#
# Distribution of this code in any form except through processmacro.org
# is prohibited without the permission of the copyright holder, as is
# distribution after modification.
#
# THIS SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
# USE OF THIS SOFTWARE IMPLIES AGREEMENT WITH THESE TERMS
#
# To activate, run this script. It may take a few minutes.
# This will produce a function called process. The other functions
# it creates cannot be accessed by the user but are used by the master
# process function. This code was not written to be easy for others to
# understand or to look pretty. It was written to work and make some things
# easier to do than they otherwise would be.
process.bcboot3<-function(databcbt,estmte,xp2,badend,priorlo,priorhi)
{
databcbt<-as.matrix(sort(databcbt))
badlo<-0;badhi<-0
pv<-matrix(as.numeric(databcbt < estmte));
pv<-sum(pv)/nrow(databcbt);ppv<-pv;
if (pv > .5){ppv<-(1-pv)}
y5<-sqrt(-2*log(ppv))
p0<-(-.322232431088);p1<-(-1);p2<-(-.342242088547);p3<-(-.0204231210245)
p4<-(-.0000453642210148);q0<-(.0993484626060);q1<-(.588581570495)
q2<-(.531103462366);q3<-(.103537752850);q4<-(.0038560700634)
xp<-y5+((((y5*p4+p3)*y5+p2)*y5+p1)*y5+p0)/((((y5*q4+q3)*y5+q2)*y5+q1)*y5+q0)
if (pv <= .5){xp<-(-xp)}
cilow<-round(nrow(databcbt)*pnorm(2*xp-xp2))
cihigh<-trunc(nrow(databcbt)*pnorm(2*xp+xp2))+1
if (cilow < 1){cilow<-1;booterr<-1;badlo<-1}
if (cihigh > nrow(databcbt)){cihigh<-nrow(databcbt);booterr<-1;badhi<-1}
llcit<-databcbt[cilow,1]
ulcit<-databcbt[cihigh,1]
if ((badlo==1) & (llcit != priorlo)){priorlo<-llcit;badend<-c(badend,llcit)}
if ((badhi==1) & (ulcit != priorhi)){priorhi<-ulcit;badend<-c(badend,ulcit)}
bootse<-sd(databcbt)
cires<-as.matrix(c(bootse,llcit,ulcit))
cires<-list(cires,badend,priorlo,priorhi)
return(cires)
}
process.pboot3<-function(databcbt,lcval,hcval)
{
databcbt<-as.matrix(sort(databcbt))
llcit<-databcbt[lcval,1]
ulcit<-databcbt[hcval,1]
bootse<-sd(databcbt)
cires<-as.matrix(c(bootse,llcit,ulcit))
return(cires)
}
process.llrtest3<-function(lm,y,x,b,basemod,iterate,converge)
{
lm<-as.matrix(lm)
btemphld<-b
llrdat<-matrix(-999,nrow(x),(nrow(lm)-sum(lm)))
llrdf<-ncol(x)-ncol(llrdat)
llrcnt<-0
for (llri in (1:nrow(lm)))
{
if (lm[llri,1]==0){llrcnt<-llrcnt+1;llrdat[,llrcnt]<-x[,llri]}
}
LL2<-process.modelest(y,llrdat,2,0,xp2,5,iterate,converge)
b<-btemphld
pvchi<-(1-pchisq((LL2-basemod),df=llrdf))
fresult<-cbind((LL2-basemod),llrdf,pvchi)
return(fresult)
}
process.describ3<-function(descdatf,type=0,quantle=1)
{
desctmp<-matrix(-999,(8-(4*type)),ncol(descdatf))
# mean, sd, min, max, 16th, 50th, 84th, dich toggle
for (jd in c(1:ncol(descdatf)))
{
descdat<-descdatf[,jd]
#get the mean, sd, minimum, and maximum */
desctmp[1,jd]<-mean(descdat)
desctmp[2,jd]<-sd(descdat)
desctmp[3,jd]<-min(descdat)
desctmp[4,jd]<-max(descdat)
if (type==0)
{
minwarn<-0;maxwarn<-0
tmp=as.numeric(descdat==desctmp[3,jd])+as.numeric(descdat==desctmp[4,jd])
desctmp[8,jd]<-as.numeric(sum(tmp)==length(tmp))
if (desctmp[3,jd]==desctmp[4,jd]){desctmp[8,jd]<-2}
descdat<-matrix(sort(descdat))
decval<-c(.16,.5,.84)
for (kd in c(1:3))
{
low<-trunc(decval[kd]*(length(descdat)+1))
lowdec<-decval[kd]*(length(descdat)+1)-low
value<-descdat[low,1]+(descdat[(low+1),1]-descdat[low,1])*lowdec
desctmp[(4+kd),jd]<-value
}
mnotev<-(1)
modvals<-matrix(desctmp[5:7,],ncol=ncol(descdatf))
if (quantle != 1)
{
desctmp[5,jd]<-desctmp[1,jd]-desctmp[2,jd]
desctmp[6,jd]<-desctmp[1,jd]
desctmp[7,jd]<-desctmp[1,jd]+desctmp[2,jd]
modvals<-matrix(desctmp[5:7,],ncol=ncol(descdatf))
mnotev<-(2)
if (modvals[1,1] < desctmp[3,1]){modvals[1,1]<-desctmp[3,1];minwarn<-1}
if (modvals[3,1] > desctmp[4,1]){modvals[3,1]<-desctmp[4,1];maxwarn<-1}
}
if (desctmp[8,jd]==1)
{modvals<-matrix(c(desctmp[3,1],desctmp[4,1]))
mnotev<-0;minwarn<-0;maxwarn<-0
}
descrtrn<-list(desctmp,modvals,minwarn,maxwarn,mnotev)
}
}
if (type==1)
{descrtrn<-list(desctmp)}
return(descrtrn)
}
process.ftest3<-function(lm,bcoef,cv=0,chr=0,brsq=0,skip=0,y,x)
{
lmat2<-as.matrix(lm)
y<-as.matrix(y)
x<-as.matrix(x)
n<-nrow(y)
if (skip==0)
{
lmat2<-as.matrix(diag(as.numeric(lm)))
lmat3<-matrix(0,nrow(lmat2),1)
for (flp in c(1:ncol(lmat2)))
{
if (sum(lmat2[,flp])==1)
{lmat3<-cbind(as.matrix(lmat3),as.matrix(lmat2[,flp]))}
}
lmat2<-as.matrix(lmat3[,2:ncol(lmat3)])
}
fratio<-(t(t(lmat2)%*%bcoef)%*%solve(t(lmat2)%*%cv%*%lmat2)%*%((t(lmat2)%*%bcoef)))/ncol(lmat2)
pfr<-(1-pf(fratio,ncol(lmat2),(n-nrow(bcoef))))
fresult<-matrix(c(fratio,ncol(lmat2),(n-nrow(bcoef)),pfr),ncol=4)
if (chr==1)
{
lmat3<-as.matrix(1-rowSums(lmat2))
xfm<-matrix(0,n,sum(lmat3))
flpc<-1
for (flp in (1:nrow(lmat3)))
{
if (lmat3[flp,1]==1){xfm[,flpc]=x[,flp];flpc<-flpc+1}
}
bfm<-solve(t(xfm)%*%xfm)%*%t(xfm)%*%y
resid<-y-(xfm%*%bfm)
sstotal<-t(y-(sum(y)/n))%*%(y-(sum(y)/n))
ssresid<-t(resid)%*%resid
rsqch<-as.numeric(brsq)-((sstotal-ssresid)/sstotal)
fresult<-matrix(c(rsqch,fresult),ncol=5)
}
ftestout<-as.matrix(fresult)
return(ftestout)
}
#type1 for ols, type2 for logistic LLR, type3 for logistic bootstrapping
process.modelest<-function(y,x,type,full,xp2,hc=5,iterate=100,converge=.00001)
{
if (type==1)
{
invxtx<-solve(t(x)%*%x)
b<-invxtx%*%t(x)%*%y
modres<-b
if (full==1)
{
n1<-nrow(x)
dfres<-(n1-(ncol(x)))
sstotal<-t(y-(sum(y)/n1))%*%(y-(sum(y)/n1))
resid=y-x%*%b
ssresid<-sum(t(resid)%*%resid)
r2<-(sstotal-ssresid)/sstotal
adjr2<-(1-((1-r2)*(n1-1)/(dfres)))
mse<-ssresid/(n1-ncol(x))
#HC covariance matrix
varb<-mse*invxtx
k3<-ncol(x)
xhc<-0
if (hc != 5)
{
xhc<-x
hat<-matrix(xhc[,1])
for (i3 in c(1:nrow(xhc)))
{
xhcm<-matrix(xhc[i3,])
hat[i3,1]<-t(xhcm)%*%invxtx%*%xhcm
}
if ((hc==0) | (hc==1))
{
for (i3 in c(1:k3)){xhc[,i3]<-xhc[,i3]*resid}
}
if ((hc==3) | (hc==2))
{
for (i3 in c(1:k3))
{xhc[,i3]<-(resid/(1-hat)^(1/(4-hc)))*xhc[,i3]}
}
if (hc==4)
{
hcmn<-matrix(4,n1,2);hcmn[,2]<-(n1*hat)/k3
minr<-apply(hcmn,1,FUN=min)
for (i3 in c(1:k3))
{
xhc[,i3]<-(resid/(1-hat)^(minr/2))*xhc[,i3]
}
}
varb<-(invxtx%*%t(xhc)%*%xhc%*%invxtx)
if (hc==1){varb<-(n1/(n1-ncol(x)))*varb}
}
seb<-sqrt(diag(varb))
trat<-b/seb
p<-2*pt(-abs(trat),df=dfres)
tval<-sqrt(dfres* (exp((dfres-(5/6))*((xp2/(dfres-(2/3)+(.11/dfres)))*(xp2/(dfres-(2/3)+(.11/dfres)))))-1))
modres<-matrix(c(modres,seb, trat,p,(b-tval*seb),(b+tval*seb)),ncol=6)
modresl<-t(matrix(c("coeff","hclab","t","p","LLCI","ULCI")))
lmat<-diag(ncol(x));lmat<-lmat[,2:ncol(lmat)]
fratio<-(t(t(lmat)%*%b)%*%solve(t(lmat)%*%varb%*%lmat)%*%((t(lmat)%*%b)))/(ncol(x)-1)
pfr<-1-pf(fratio,(ncol(x)-1),dfres)
modsum=matrix(c(sqrt(r2),r2,mse,fratio,(ncol(x)-1),dfres,pfr))
modsuml=matrix(c("R","R-sq","MSE","hcflab","df1","df2", "p"))
modretrn<-list(modres,modresl,modsum,modsuml,b,varb,tval,resid)
return(modretrn)
}
if (full==0){return(modres)}
}
#for logistic Y model
if ((type==2) | (type==3))
{
xlp<-x;ylp<-as.matrix(y)
pt2<-matrix((sum(ylp)/nrow(ylp)),nrow(ylp),1)
if ((type==2)|(type==3)) {LL3<-(ylp*log(pt2)+(1-ylp)*log(1-pt2))}
LL3<-(-2*sum(LL3))
bt1<-matrix(0,ncol(xlp),1);LL1<-0
pt1<-matrix(0.5,nrow(ylp),1);pt1lp<-pt1
for (jjj in (1:iterate))
{
xlptmp<-t(xlp)
vecprb<-(pt1lp*(1-pt1lp))
for (kkk in (1:ncol(xlp))){xlptmp[kkk,]<-xlptmp[kkk,]*t(vecprb)}
b<-bt1+solve(xlptmp%*%xlp)%*%t(xlp)%*%(ylp-pt1lp)
if ((type==2) | (type==3))
{
xlpb<-xlp%*%b
xlpbt<-as.numeric(xlpb > -709.7)
xlpb709<-((1-xlpbt)*(-709.7))
xlpb<-((xlpb*xlpbt)+xlpb709)
pt1lp<-1/(1+exp(-(xlpb)))
}
itprob<-sum((pt1lp < .00000001) | (pt1lp > .9999999))
if (itprob > 0)
{
for (kkk in (1:nrow(pt1lp)))
{
if (pt1lp[kkk,1] > .9999999){pt1lp[kkk,1]<-.9999999}
if (pt1lp[kkk,1] < .00000001){pt1lp[kkk,1]<-.00000001}
}
itprob<-0
}
if (itprob==0)
{
if ((type==2)|(type==3)){LL<-(ylp*log(pt1lp)+(1-ylp)*log(1-pt1lp))}
LL2<-(-2*sum(LL))
}
if (abs(LL1-LL2) < converge)
{
if (full==1)
{
xlptmp<-t(xlp)
vecprb<-(pt1lp*(1-pt1lp))
for (kkk in (1:ncol(xlp))){xlptmp[kkk,]<-xlptmp[kkk,]*t(vecprb)}
varb<-solve(xlptmp%*%xlp)
seb<-matrix(sqrt(diag(varb)))
}
break
}
bt1<-b;LL1<-LL2
}
modres<-b
if (jjj > iterate)
{
itprob<-2
if (booting==0){iterrmod<-1}
if (booting==1){bootiter==1}
if (itprobtg==0)
{
itprobtg<-1;errcode[errs,1]<-47;errs<-errs+1
if ((booting==0) & (full==1))
{
pt1lpc<-(pt1lp*(1-pt1lp))
vt1<-diag(pt1lpc)
varb<-solve(t(xlp)%*%vt1%*%xlp)
seb<-matrix(sqrt(diag(varb)))
}
}
}
if (full==1)
{
trat<-b/seb
dfres<-nrow(xlp)
p<-2*(1-pnorm(abs(trat)))
modres<-cbind(modres,seb,trat,p)
modres<-matrix(c(modres,(b-xp2*seb),(b+xp2*seb)),ncol=6)
pvchi<-(1-pchisq((LL3-LL2),df=(nrow(modres)-1)))
mcF<-(LL3-LL2)/LL3
cox<-1-exp(-(LL3-LL2)/nrow(xlp))
nagel<-cox/(1-exp(-(LL3)/nrow(xlp)))
modsum<-matrix(c(LL2,(LL3-LL2),(nrow(modres)-1),pvchi, mcF,cox,nagel))
modsuml<-matrix(c("-2LL","ModelLL", "df", "p", "McFadden", "CoxSnell", "Nagelkrk"))
modresl<-t(matrix(c("coeff","se","Z","p","LLCI","ULCI")))
modretrn<-list(modres,modresl,modsum,modsuml,b,varb,xp2)
return(modretrn)
}
if ((full==0) & (type==2)){return(LL2)}
if ((full==0) & (type==3)){return(modres)}
}
}
process.dummy3<-function(dd)
{
uq<-unique(dd)
uq<-matrix(unlist(uq[1]))
dummy<-matrix(0,nrow(dd),nrow(uq))
uq<-matrix(sort(uq))
uq2<-matrix(seq(1:nrow(uq)))
for (i in c(1:nrow(dd)))
{for (j in c(1:nrow(uq)))
{if (dd[i,1]==uq[j,1])
{dummy[i,uq2[j,1]]<-1}
}
}
return(dummy)
}
process.makdummy<-function(dd,method,custcov=0,custcode=999)
{
dd<-dd[order(dd[,2]),]
newrow<-dd[,1]
dd<-dd[,2]
dd<-as.data.frame(dd)
dummy<-process.dummy3(dd)
uq<-unique(dd);uq<-matrix(unlist(uq[1]))
criterrd<-0;errcode5<-0;errcode4<-0;errcode6<-0
nvls<-ncol(dummy)
nnvls<-colSums(dummy)
mnvls<-min(nnvls)
nnvls<-matrix(sort(uq))
conmat1<-1
if (mnvls < 2){errcode5<-1;criterrd<-1}
if (nvls > 9){errcode4<-1;criterrd<-1}
x<-0;dummat<-0
if (criterrd==0)
{
dumok<-1
if (method > 0)
{
x<-dummy[,2:ncol(dummy)]
nx<-ncol(x)
minus1<-matrix(-1,1,ncol(x))
if (method==4)
{
for (k in (1:nrow(dd)))
{shole<-sum(x[k,])
if (shole==0)
{x[k,]<-minus1}}
}
if ((method==2) | (method==3) | (method==5))
{
for (k in (1:nrow(dd)))
{shole<-sum(x[k,])
if (shole > 0)
{
for (i in (1:ncol(x)))
{if (x[k,i]==0){x[k,i]<-1} else{break}
}
}
}
if (method==3)
{
conmat1=c(-8,1,1,1,1,1,1,1,1,0,-7,1,1,1,1,1,1,1,0,0,-6,1,1,1,1,1,1,0,0,0,-5,1,1,1,1,1,0,0,0,0,-4,1,1,1,1,0,0,0,0,0,-3,1,1,1,0,0,0,0,0,0,-2,1,1,0,0,0,0,0,0,0,-1,1)
conmat1<-t(matrix(conmat1,9,8))
for (i in (1:8)){conmat1[i,]=conmat1[i,]/(10-i)}
conmat1<-t(conmat1[(10-nvls):8,(10-nvls):9])
for (k in (1:nrow(dd)))
{shole<-sum(x[k,]);x[k,]=conmat1[(shole+1),]}
}
}
if (method==5)
{
if (ncol(custcode) != (nvls*(nvls-1)))
{errcode6<-1}
if (ncol(custcode)==(nvls*(nvls-1)))
{
conmat1<-matrix(0,nvls,(nvls-1));cnt<-1
for (i in (1:nvls))
{
for (k in (1:(nvls-1)))
{conmat1[i,k]<-custcode[1,cnt];cnt<-cnt+1}
}
for (k in (1:nrow(dd))){x[k,]<-conmat1[(sum(x[k,])+1),]} #check this
}
}
xskip<-1
dummat<-matrix(0,(nx+1),nx)
dummat[(2:nrow(dummat)),]<-diag(nx)
if (method==4){dummat[1,]<-minus1}
if (method==2)
{for (i in 2:nrow(dummat))
{for (j in (1:(i-1))){dummat[i,j]<-1}}
}
if (method==3){dummat<-conmat1}
if ((method==5) & (errcode6==0)){dummat<-conmat1}
dummat<-cbind(nnvls,dummat)
}
x<-cbind(newrow,x)
x<-x[order(x[,1]),]
}
dummrn<-list(x,dummat,nvls,nnvls,errcode4,errcode5,errcode6)
return(dummrn)
}
process<-function(data,y="xxxxx",x="xxxxx",m="xxxxx",w="xxxxx",z="xxxxx",cov="xxxxx",
model=999,converge=.00001,iterate=100,hc=5,jn=0,effsize=0,stand=0,xmtest=0,normal=0,
mdichok=0,contrast=999,modelbt=0,matrices=0,covmy=0,covcoeff=0,boot=5000,mc=0,
intprobe=0.1,plot=0,total=0,save=0,mcx=0,mcw=0,mcz=0,moments=0,progress=1,
bmatrix=-999,wmatrix=-999,zmatrix=-999,wzmatrix=-999,cmatrix=-999,xcatcode=999,
wcatcode=999,zcatcode=999,wmodval=999,zmodval=999,center=0,conf=95,seed=-999,
decimals=9.4,maxboot=0,modelres=0,bc=0,outscreen=1,activate=0,describe=0,listmiss=0,
linsum=-999,xmint=0,xrefval=999,coval=-999,cdeval=-999)
{
#all this is initiation of variables and matrices
ranseed<-0;
if (seed != -999)
{seed<-trunc(abs(seed));set.seed(seed)}
wnames<-w;znames<-z;mcerpt<-0;wiscov<-0;ziscov<-0;itprobtg<-0;
v2tag<-0;maxwwarn<-0;minwwarn<-0;maxzwarn<-0;minzwarn<-0
toomany<-0;wdich<-0;zdich<-0;wnotev<-0;znotev<-0;singlr<-0
nxpval<-1;nwpval<-1;nzpval<-1;errs<-1;notes<-1;criterr<-0
novar<-0;adjust<-0;ncs<-0;serial<-0;sobelok<-0;hasw<-0;ydich<-0;
hasz<-0;printw<-0;printz<-0;xmint<-as.numeric(xmint==1);wmodcust<-0;zmodcust<-0
booting<-0;bootiter<-0;iterrmod<-0;model<-trunc(model)
errcode<-matrix(0,100,1);notecode<-matrix(0,100,1)
iterate<-abs(trunc(iterate));converge=abs(converge);badend<-0;booterr<-0;
itprobtg<-0;v2tag<-0;maxwwarn<-0;minwwarn<-0;maxzwarn<-0
minzwarn<-0;toomany<-0;wdich<-0;zdich<-0;wnotev<-0;znotev<-0
nws<-0;nzs<-0;nms<-0;nys<-0;nxs<-0;maxresm<-9;bc<-as.numeric(bc==1);progress<-as.numeric(progress==1)
mcxok<-0;mcwok<-0;mczok<-0;xprod<-0;zprod<-0;wprod<-0;modcok<-0;alttotal=0;bc<-as.numeric(bc==1)
jn<-as.numeric(jn==1);effsize<-as.numeric(effsize==1);maxboots=abs(trunc(maxboot))
normal<-as.numeric(normal==1);xmtest<-as.numeric(xmtest==1);modelres<-as.numeric(modelres==1)
stand<-as.numeric(stand==1);outscreen<-as.numeric(outscreen==1);activate<-as.numeric(activate==1)
xrefvals<-t(matrix(xrefval));xcontcf<-0;xscaling<-1;
cdeval<-t(matrix(cdeval))
cuscoval=0
if (model==74)
{errcode[errs,1]<-7;errs<-errs+1;criterr<-1}
if ((xmint==1) & (model != 4))
{errcode[errs,1]<-63;errs<-errs+1;criterr<-1}
if ((xmint==1) & (model==4))
{
w<-x;model<-74;intprobe<-1
notecode[notes,1]<-32;
notes<-notes+1
if ((effsize==1) | (stand==1))
{notecode[notes,1]<-34;notes<-notes+1;stand<-0;effsize<-0}
if (center != 0)
{center<-0;errcode[errs,1]<-71;errs<-errs+1;criterr<-1}
}
describe<-as.numeric(describe==1);listmiss<-as.numeric(listmiss==1);
if (stand==1) {effsize<-1}
pstog<-0;sobelok<-0;mdichok=as.numeric(mdichok==1)
resultm<-matrix(99999,1,maxresm)
linsum<-t(matrix(linsum));
nlinsum<-ncol(linsum);
if (linsum[1,1]==-999){nlinsum<-0}
#contrast matrix
contrast<-matrix(contrast);
contrast<-t(contrast)
ncontr<-ncol(contrast)
if (contrast[1,1]==999) {ncontr<-1;contrast[1,1]<-0}
if (ncontr==1)
{
contrast<-trunc(contrast)
if ((contrast[1,1] > 2) | (contrast[1,1] < 0))
{ncontr<-1;contrast[1,1]<-0}
}
if (ncontr > 1)
{
contvec<-contrast;contrast[1,1]<-3
if (((model==2) | (model==3)) & (nms==0))
{
if (ncontr==4)
{
contvec<-t(matrix(contvec,2,2))
contrast[1,1]<-0;modcok<-1;wcontval<-matrix(contvec[,1]);zcontval<-matrix(contvec[,2])
}
if (ncontr !=4)
{
notecode[notes,1]<-19;notes<-notes+1
contrast[1,1]<-0
}
}
}
contrast<-contrast[1,1]
if ((xmint==1) & (contrast != 0))
{contrast<-0;notecode[notes,1]<-37;notes<-notes+1}
modelbt<-as.numeric(modelbt==1);matrices<-as.numeric(matrices==1)
covcoeff<-as.numeric(covcoeff==1);covmy<-trunc(covmy)
if ((covmy < 0) | (covmy > 2)) {covmy<-0}
boot<-abs(trunc(boot));mc=abs(trunc(mc));hc=trunc(hc)
if ((intprobe < 0) | (intprobe > 1))
{intprobe<-0.10}
plot<-trunc(plot)
if ((plot < 0) | (plot > 2)) {plot<-0}
total<-as.numeric(total==1)
dototal<-0
saveboot<-as.numeric((save==1)|(save==3))
saveest<-as.numeric(save > 1)
if (saveest==1){intprobe=1}
if ((hc >=0) & (hc < 5)) {notecode[notes,1]<-4;notes=notes+1}
if ((hc > 5) | (hc < 0)) {hc=5}
####dont use these when y is dichotomous
hclab<-matrix(c("se(HC0)","se(HC1)","se(HC2)","se(HC3)","se(HC4)","se"))
hclab<-hclab[(hc+1),1]
hcflab<-matrix(c("F(HC0)","F(HC1)","F(HC2)","F(HC3)","F(HC4)","F"))
hcflab<-hcflab[(hc+1),1]
mcw=trunc(mcw);mcz=trunc(mcz);mcx=trunc(mcx);
if ((mcx > 0) & (mcx < 3) &(model==74)) {mcw<-mcx;xscaling<-1}
if ((mcx > 2) & (model==74))
{errcode[errs,1]<-65;errs<-errs+1;criterr<-1}
if ((model==74) & (normal==1))
{notecode[notes,1]<-33;normal<-0;notes<-notes+1}
if ((mcx > 0) & (contrast > 0))
{notecode[notes,1]<-28;notes<-notes+1;contrast<-0}
nxvls<-1;nmvls<-1;nwvls<-1;nzvls<-1
paths<-matrix(999);pathsw<-matrix(999);pathsz<-matrix(999);
pathswz<-matrix(999);pathsmod<-matrix(999);pathtype<-matrix(999);obscoeff<-999;
pathsdv=matrix(" ");quantile<-1;moments=as.numeric(moments==1)
if (moments==1){quantile<-0}
bmatrix=t(matrix(bmatrix));wmatrix=t(matrix(wmatrix));zmatrix=t(matrix(zmatrix));
wzmatrix=t(matrix(wzmatrix));cmatrix=t(matrix(cmatrix));xcatcode=t(matrix(xcatcode));
wcatcode=t(matrix(wcatcode));zcatcode=t(matrix(zcatcode));
needed<-0
decimals<-paste("%",decimals,"f",sep='')
if ((trunc(conf) >= 100) | (trunc(conf <= 50)))
{conf=95;notecode[notes,1]<-2;notes=notes+1}
if ((model >= 0) & (model < 4) & (modelbt==0)) {boot<-0;mc<-0;bc<-0;saveboot<-0}
if ((boot > 0) & (mc > 0)) {boot<-0;bc<-0}
if ((boot < 1000) & (boot > 0) & (mc==0)){boot=5000}
if ((mc < 1000) & (mc > 0) & (boot==0)){mc=5000}
#if ((model > 0) & (model < 4) & (boot = 98765) & (modelbt=1)) then;do;mc=0;boot=5000;end;
#if ((model > 0) & (model < 4) & ((boot = 98765) | (mc > 0))) then;do;boot=0;mc=0;bc=0;end;
#if ((boot = 98765) & (mc = 0)) then;do;boot=5000;end;
p0<- -.322232431088;p1<- -1;p2<- -.342242088547;p3<- -.0204231210245;
p4<- -.0000453642210148;q0<- .0993484626060;q1<- .588581570495;
q2<- .531103462366;q3<- .103537752850;q4<- .0038560700634;
priorlo<-(-9999999);priorhi<-9999999
alpha2<-(1-(conf/100))/2;cilm<-alpha2*2;y5<-sqrt(-2*log(alpha2));
xp2=(y5+((((y5*p4+p3)*y5+p2)*y5+p1)*y5+p0)/((((y5*q4+q3)*y5+q2)*y5+q1)*y5+q0))
medlb=matrix(c(" M1 :"," M2 :"," M3 :"," M4 :"," M5 :"," M6 :"," M7 :"," M8 :"," M9 :"," M10 :"))
medlb2=matrix(c("(M1)","(M2)","(M3)","(M4)","(M5)","(M6)","(M7)","(M8)","(M9)","(M10)"))
xlb=matrix(c("X1 :","X2 :","X3 :","X4 :","X5 :","X6 :","X7 :","X8 :","X9 :","X10:"))
highlbw=matrix(c("M1*W","M2*W","M3*W","M4*W","M5*W","M6*W","M7*W","M8*W","M9*W","M10*W"))
if (xmint==1)
{highlbw=matrix(c("M1*X","M2*X","M3*X","M4*X","M5*X","M6*X","M7*X","M8*X","M9*X","M10*X"))}
highlbz=matrix(c("M1*Z","M2*Z","M3*Z","M4*Z","M5*Z","M6*Z","M7*Z","M8*Z","M9*Z","M10*Z"))
highlbwz=matrix(c("M1*W*Z","M2*W*Z","M3*W*Z","M4*W*Z","M5*W*Z","M6*W*Z","M7*W*Z","M8*W*Z","M9*W*Z","M10*W*Z"))
highlbx=matrix(c("M1*X","M2*X","M3*X","M4*X","M5*X","M6*X","M7*X","M8*X","M9*X","M10*X"))
highlbbt=matrix(c("BOTH(M1)","BOTH(M2)","BOTH(M3)","BOTH(M4)","BOTH(M5)","BOTH(M6)","BOTH(M7)","BOTH(M8)","BOTH(M9)","BTH(M10)"))
skipwz=0
xnck=matrix(x);ynck=matrix(y);wnck=matrix(w);znck=matrix(z);mnck=matrix(m);cnck=matrix(cov)
if ((nrow(xnck)>1) | (nrow(ynck)>1) | (nrow(wnck)>1) | (nrow(znck)>1))
{errcode[errs,1]<-3;errs<-errs+1;criterr<-1}
validm=matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1))
dim(validm)<-c(1,92)
# check for major errors in syntax
if (activate==1)
{errcode[errs,1]<-60;errs<-errs+1;criterr<-1}
if (criterr==0)
{
if ((model > 0) & (model < 93))
{
if (validm[1,model]==0)
{
errcode[errs,1]<-6;errs<-errs+1;criterr<-1
}
}
if (((model > 92) | (model < 0)) & (model != 999))
{errcode[errs,1]<-7;errs<-errs+1;criterr<-1}
if ((model==999) & (bmatrix[1,1]==-999))
{errcode[errs,1]<-24;errs<-errs+1;criterr<-1}
if ((model != 999) & (bmatrix[1,1] != -999))
{errcode[errs,1]<-25;errs<-errs+1;criterr<-1}
if (((model==74) | ((model > 0) & (model < 4))) & ((wmatrix[1,1] !=-999) | (zmatrix[1,1] != -999) | (wzmatrix[1,1] != -999)))
{errcode[errs,1]<-41;errs<-errs+1;criterr<-1}
if ((y=="xxxxx") | (x=="xxxxx"))
{errcode[errs,1]<-1;errs<-errs+1;criterr<-1}
if ((mnck[1,1]=="xxxxx") & (model > 3))
{errcode[errs,1]<-8;errs<-errs+1;criterr<-1}
}
#end of check for major errors in syntax
#A loop reads data and does some other things
if (criterr==0)
{
#read y data
ytmp<-data[y];nys<-ncol(ytmp);needed<-nys
ynames<-matrix(y);n<-nrow(ytmp);varnames<-matrix(ynames)
dat<-ytmp
modelvar<-matrix(c(model,ynames))
if (xmint==1)
{modelvar[1,1]="4"}
if (model==999){modelvar[1,1]="CUSTOM"}
#read x data
xtmp<-data[x];
nxs<-ncol(xtmp);needed<-needed+nxs;
dat<-cbind(dat,xtmp)
xnames<-matrix(x);n<-nrow(xtmp);xcatlab<-xnames;
varnames<-matrix(c(varnames,xnames))
modelvar<-matrix(c(modelvar,xnames))
if (nxs==1){modelvlb<-matrix(c("Model :"," Y :"," X :"))}
#read m data
if (mnck[1,1] != "xxxxx")
{
mtmp<-data[m]
nms<-ncol(mtmp)
mnames<-matrix(m)
mprod<-matrix(0,1,nms)
n<-nrow(mtmp)
needed<-needed+nms
varnames<-matrix(c(varnames,mnames))
dat<-cbind(dat,mtmp)
modelvar<-matrix(c(modelvar,mnames))
x2m<-matrix(0,99,nms)
x2m<-matrix(0,99,nms)
x2y<-matrix(0,99,nms)
onem<-matrix(1,nms,1)
if ((nms > 1) & (nms < 11))
{modelvlb<-matrix(c(modelvlb,medlb[1:nms,1]))}
if (nms==1)
{modelvlb<-matrix(c(modelvlb," M :"))}
if ((nms > 0) & (model < 4)){errcode[errs,1]<-9;errs<-errs+1;criterr<-1}
}
#read w data
wlocatet<-0;wlocate<-0
if (w != "xxxxx")
{
if (xmint==0)
{wtmp<-data[w];wnames<-matrix(w)}
if (xmint==1)
{wtmp<-data[x];wnames<-matrix(x)}
nws=ncol(wtmp);n<-nrow(wtmp)
dat<-cbind(dat,wtmp)
wcatlab<-wnames
varnames<-matrix(c(varnames,wnames))
wlocate<-nrow(varnames)
if (model==74)
{
wlocatet<-1;
if (xnames != wnames)
{errcode[errs,1]<-45;errs<-errs+1;criterr<-1}
}
if (xmint != 1)
{modelvar<-matrix(c(modelvar,wnames))
modelvlb<-matrix(c(modelvlb," W :"))}
}
#read z data
if (z != "xxxxx")
{
ztmp<-data[z];nzs<-ncol(ztmp);n<-nrow(ztmp);
dat<-cbind(dat,ztmp)
znames<-matrix(z);zcatlab<-znames;
varnames<-matrix(c(varnames,znames))
modelvar<-matrix(c(modelvar,znames))
modelvlb<-matrix(c(modelvlb," Z :"))
}
#read cov data
if (cnck[1,1] != "xxxxx")
{
ctmp<-data[cov];ncs<-ncol(ctmp);n<-nrow(ctmp);
dat<-cbind(dat,ctmp)
covnames<-matrix(cov);varnames<-matrix(c(varnames,covnames));
}
if (((model==80) | (model==81)) & ((nms < 3) | (nms > 6)))
{errcode[errs,1]<-32;errs<-errs+1;criterr<-1}
if ((model==82) & (nms != 4))
{errcode[errs,1]<-33;errs<-errs+1;criterr<-1}
if (nms > 10)
{errcode[errs,1]<-37;errs<-errs+1;criterr<-1}
if (((model==6) | ((model > 82) & (model < 999))) & ((nms < 2) | (nms > 6)))
{errcode[errs,1]<-34;errs<-errs+1;criterr<-1}
#check for redundant variable names
match<-0;match2<-0;mcwzcov<-0
for (i in c(1:(nrow(varnames)-1)))
{
for (j in c((i+1):nrow(varnames)))
{
if (varnames[i]==varnames[j])
{
if (i < (nxs+nms+nys+1)){match2<-match2+1}
if ((wlocatet==1) & (i==2) & (j==wlocate)){match2<-match2-1}
if ((wnames==znames) & ((nws > 0) | (nzs > 0))){match<-match2+1}
if ((i < (nrow(varnames)-ncs+1)) & (j > (ncol(varnames)-ncs)))
{
if ((varnames[j]==wnames) & (mcw==0))
{match<-0;wiscov<-(j-(nrow(varnames)-ncs))}
if ((varnames[j]==wnames) & (mcw !=0)){mcwzcov<=0}
if ((varnames[j]==znames) & (mcz==0))
{match<-0;ziscov<-(j-nrow(varnames)-ncs)}
if ((varnames[j]==znames) & (mcz !=0)){mcwzcov<-0}
}
}
}
}
if ((match2 > 0) | (match==1))
{errcode[errs,1]<-2;errs<-errs+1;criterr<-1}
if (mcwzcov==1)
{errcode[errs,1]<-50;errs<-errs+1;criterr<-1}
#check for factors
hello<-as.numeric(sapply(dat,is.factor))
nfacs<-sum(hello)
if (nfacs > 0){errcode[errs,1]<-53;errs<-errs+1;criterr<-1}
if (criterr==0)
{
#listwise deletion
ninit<-nrow(dat);rownum<-seq(1:nrow(dat));dat<-cbind(rownum,dat)
datms<-is.na(dat)
datms<-matrix(as.numeric(datms),nrow(datms))
datms<-matrix(rowSums(datms))
missrow<-0;
for (i in 1:ninit)
{if (datms[i,1] > 0){missrow<-cbind(missrow,i)}}
missrow<-matrix(missrow)
if (nrow(missrow) > 1)
{
missrow<-missrow[2:nrow(missrow)]
notecode[notes,1]<-29;
notes<-notes+1;
}
missrow<-t(matrix(missrow))
dat<-na.omit(dat);n<-nrow(dat);nmiss=ninit-n;
if (n < 5)
{errcode[errs,1]<-62;errs<-errs+1;criterr<-1}
if (criterr==0)
#startit
{
rownum<-dat[,1];dat<-dat[,2:ncol(dat)]
#extract the data back into vectors or matrices
ytmp=as.data.frame(dat[,1:nys])
desctmp2<-process.describ3(ytmp,0,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
ysd<-desctmp[2,1];ovsd<-ysd;ydich<-0
if (desctmp[8,1]==2){errcode[errs,1]<-15;errs<-errs+1;criterr<-1;novar<-1}
if (desctmp[8,1]==1)
{
ydich<-1;
if (total==1){total<-0;notecode[notes,1]<-24;notes<-notes+1}
if (effsize==1){effsize<-0;notecode[notes,1]<-25;notes<-notes+1}
if (model==74){errcode[errs,1]<-72;errs<-errs+1;criterr<-1}
omx<-max(ytmp);omn<-min(ytmp)
ytmp<-matrix(as.numeric(ytmp==omx),ncol=nys)
dat[,1:nys]<-matrix(as.numeric(dat[,1:nys]==omx),ncol=nys)
rcd<-c(omn,omx,0,1);dim(rcd)<-c(2,2)
}
xtmp<-as.data.frame(dat[,(nys+1):(nys+nxs)])
desctmp2<-process.describ3(xtmp,0,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
xsd<-desctmp[2,1]
if ((desctmp[8,1]==2) & (novar==0))
{errcode[errs,1]<-15;errs<-errs+1;criterr<-1;novar<-1}
xmodvals<-matrix(unlist(desctmp2[2]))
xdich<-desctmp[8,1]
xmx=max(xtmp);xmn=min(xtmp)
if ((mcx > 0) & (xrefvals[1,1] != 999) & (xmint==1) & (model== 74))
{notecode[notes,1]<-36;notes=notes<-1}
if (mcx==0)
{
if ((ncol(xrefvals)>2) & (model==74) & (xmint==1))
{errcode[errs,1]<-67;errs<-errs+1;criterr<-1}
if ((model==74) & (xmint==1))
{
if ((xrefvals[1,1]==999) & (nxvls==1) & (xdich==0))
{errcode[errs,1]<-66;errs=errs<-1;criterr<-1}
if ((xrefvals[1,1]==999) & (xdich==1))
{xrefvals<-t(matrix(c(xmn,xmx)));xscaling<-xrefvals[1,2]-xrefvals[1,1]}
if ((ncol(xrefvals)==1) & (xrefvals[1,1] != 999))
{
if (xdich==0)
{
xrefvals<-t(matrix(c(xrefvals,(xrefvals[1,1]+1))))
xscaling<-xrefvals[1,2]-xrefvals[1,1]
}
if (xdich==1)
{
if ((xrefvals[1,1] != xmx) & (xrefvals[1,1] != xmn))
{errcode[errs,1]<-70;errs<-errs+1;criterr<-1}
if (xrefvals[1,1]==xmx)
{xrefvals<-t(matrix(c(xrefvals,xmn)));xscaling<-xrefvals[1,2]-xrefvals[1,1]}
if (xrefvals[1,1]==xmn)
{xrefvals<-t(matrix(c(xrefvals,xmx)));xscaling<-xrefvals[1,2]-xrefvals[1,1]}
}
}
if (ncol(xrefvals)==2)
{
xscaling<-xrefvals[1,2]-xrefvals[1,1]
if (xdich==1)
{
xreferr<-1
if (((xrefvals[1,1]==xmx) & (xrefvals[1,2]==xmn)) | ((xrefvals[1,1]==xmn) & (xrefvals[1,2]==xmx)))
{xreferr<-0}
if (xreferr==1)
{errcode[errs,1]<-70;errs<-errs+1;criterr<-1}
}
}
}
}
if ((xmint==1) & (model==74) & (mcx==0))
{xmodvals=t(xrefvals);xcontcf=1}
nxpval<-nrow(xmodvals)
xprobval<-as.matrix(xmodvals)
if ((xdich==1) & (mcx > 0))
{mcx<-0;errcode[errs,1]<-52;errs<-errs+1;criterr<-1}
#if ((model==74) & (xdich==1)){xmint=1}
if (nms > 0)
{
mtmp<-as.data.frame(dat[,(nys+nxs+1):(nys+nxs+nms)])
desctmp2<-process.describ3(mtmp,0,quantile)
desctmp<-matrix(unlist(desctmp2[1]),ncol=ncol(mtmp))
ovsd<-matrix(c(desctmp[2,],ysd))
medmeans<-cdeval;
if ((cdeval[1,1] != -999) & (ncol(medmeans) != nms) & (model==74))
{errcode[errs,1]<-64;errs<-errs+1;criterr<-1}
if ((cdeval[1,1]==-999) & (model==74))
{medmeans<-t(matrix(desctmp[1,]))}
if ((cdeval[1,1] != -999) & (model==74) & (criterr==0))
{notecode[notes,1]<-31;notes<-notes+1}
zzzz<-rowSums(desctmp)
if ((zzzz[8]>0) & (mdichok != 1))
{errcode[errs,1]<-43;errs<-errs+1;criterr<-1}
mmodvals<-matrix(unlist(desctmp2[2]),ncol=ncol(mtmp))
mprobval<-mmodvals
}
if (nws > 0)
{
wtmp<-as.data.frame(dat[,(nys+nxs+nms+1):(nys+nxs+nms+nws)])
desctmp2<-process.describ3(wtmp,0,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
if ((desctmp[8,1]==2) & (novar==0))
{errcode[errs,1]<-15;errs<-errs+1;criterr<-1;novar<-1}
wmodvals<-matrix(unlist(desctmp2[2]))
wdich<-desctmp[8,1]
if ((wdich==1) & (mcw > 0))
{mcw<-0;errcode[errs,1]<-52;errs<-errs+1;criterr<-1}
wmin<-desctmp[3,1]
wmax<-desctmp[4,1]
minwwarn<-matrix(unlist(desctmp2[3]));maxwwarn<-matrix(unlist(desctmp2[4]))
wnotev<-matrix(unlist(desctmp2[5]))
wmodval<-t(matrix(wmodval))
if ((xmint==1) & (model==74) & (mcx==0))
{wmodval<-xrefvals}
nwcontr<-ncol(wmodval)
if (wmodval[1,1] != 999)
{
wmodvals<-matrix(wmodval[1,1]);wmodcust<-1
if (nwcontr > 1){wmodvals<-t(wmodval)}
minwwarn<-0;maxwwarn<-0;wnotev<-0
}
wprobval<-as.matrix(wmodvals)
nwpval<-nrow(wmodvals)
}
if (nzs > 0)
{
ztmp<-as.data.frame(dat[,(nys+nxs+nms+nws+1):(nys+nxs+nms+nws+nzs)])
desctmp2<-process.describ3(ztmp,0,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
if ((desctmp[8,1]==2) & (novar==0))
{errcode[errs,1]<-15;errs<-errs+1;criterr<-1;novar<-1}
zmodvals<-matrix(unlist(desctmp2[2]))
zdich<-desctmp[8,1]
if ((zdich==1) & (mcz > 0))
{mcz<-0;errcode[errs,1]<-52;errs<-errs+1;criterr<-1}
zmin<-desctmp[3,1]
zmax<-desctmp[4,1]
minzwarn<-matrix(unlist(desctmp2[3]));maxzwarn<-matrix(unlist(desctmp2[4]));
znotev<-matrix(unlist(desctmp2[5]))
zmodval<-t(matrix(zmodval))
nzcontr<-ncol(zmodval)
if (zmodval[1,1] != 999)
{
zmodvals<-matrix(zmodval[1,1]);zmodcust<-1
if (nzcontr > 1){zmodvals<-t(zmodval)}
minzwarn<-0;maxzwarn<-0;znotev<-0
}
zprobval<-as.matrix(zmodvals)
nzpval<-nrow(zmodvals)
}
if (ncs > 0)
{
ctmp<-as.data.frame(dat[,(nys+nxs+nms+nws+nzs+1):(nys+nxs+nms+nws+nzs+ncs)])
covmean2<-process.describ3(ctmp,1,quantile)
covmeans<-matrix(unlist(covmean2[1]),ncol=ncs);covmeans<-matrix(covmeans[1,],nrow=1)
}
coval<-t(matrix(coval))
if ((coval[1,1] != -999) & (ncol(coval) != ncs) & (model==74))
{errcode[errs,1]<-69;errs<-errs+1;criterr<-1}
if ((coval[1,1] != -999) & (criterr==0) & (model==74))
{notecode[notes,1]<-35;notes<-notes+1;cuscoval<-1}
n<-nrow(ytmp)
ones<-matrix(1,n,1)
modresid<-matrix(9999,n,1)
#creat codes for categorical variables
if ((nws > 0) & (mcw > 0))
{
tmp<-cbind(rownum,wtmp[,1])
dumtmp<-process.makdummy(tmp,mcw,2,wcatcode)
wmodvals<-matrix(unlist(dumtmp[4]))
nwpval<-nrow(wmodvals)
errcode4<-unlist(dumtmp[5])
errcode5<-unlist(dumtmp[6])
errcode6<-unlist(dumtmp[7])
if (errcode4==1){errcode[errs,1]<-4;errs<-errs+1;criterr<-1}
if (errcode5==1){errcode[errs,1]<-5;errs<-errs+1;criterr<-1}
if (errcode6==1){errcode[errs,1]<-39;errs<-errs+1;criterr<-1}
if (criterr==0)
{
nvls<-unlist(dumtmp[3])
nwvls<-nvls-1
minwwarn<-0;maxwwarn<-0;wnotev<-0
wtmp<-matrix(unlist(dumtmp[1]),ncol=(nwvls+1))
wtmp<-wtmp[,2:ncol(wtmp)];wtmp<-as.data.frame(wtmp)
wcatlab<-c("W1","W2","W3","W4","W5","W6","W7","W8","W9")
if (xmint==1)
{wcatlab<-c("X1","X2","X3","X4","X5","X6","X7","X8","X9")}
wcatlab<-matrix(wcatlab)
mcwok<-1
dummatw<-matrix(unlist(dumtmp[2]),ncol=(nwvls+1),nrow=(nwvls+1))
wprobval<-dummatw[,2:ncol(dummatw)]
if (modcok==1)
{
wcontval<-matrix(-999,2,ncol(wprobval))
temp<-0
for (i in (1:2))
{
for (j in (1:nrow(dummatw)))
{
if (contvec[i,1]==dummatw[j,1])
{wcontval[i,]<-wprobval[j,];temp<-temp+1}
}
}
if (temp < 2)
{notecode[notes,1]<-20;notes<-notes+1;modcok<-0}
}
if ((wmodval[1,1] != 999) & (xmint != 1))
{notecode[notes,1]<-9;notes<-notes+1}
}
}
if ((nzs > 0) & (mcz > 0))
{
tmp<-cbind(rownum,ztmp[,1])
dumtmp<-process.makdummy(tmp,mcz,3,zcatcode)
zmodvals<-matrix(unlist(dumtmp[4]))
nzpval<-nrow(zmodvals)
errcode4<-unlist(dumtmp[5])
errcode5<-unlist(dumtmp[6])
errcode6<-unlist(dumtmp[7])
if (errcode4==1){errcode[errs,1]<-4;errs<-errs+1;criterr<-1}
if (errcode5==1){errcode[errs,1]<-5;errs<-errs+1;criterr<-1}
if (errcode6==1){errcode[errs,1]<-40;errs<-errs+1;criterr<-1}
if (criterr==0)
{
nvls<-unlist(dumtmp[3])
nzvls<-nvls-1
minzwarn<-0;maxzwarn<-0;znotev<-0
ztmp<-matrix(unlist(dumtmp[1]),ncol=(nzvls+1))
ztmp<-ztmp[,2:ncol(ztmp)];ztmp<-as.data.frame(ztmp)
zcatlab<-c("Z1","Z2","Z3","Z4","Z5","Z6","Z7","Z8","Z9");zcatlab=matrix(zcatlab)
mczok<-1
dummatz<-matrix(unlist(dumtmp[2]),ncol=(nzvls+1),nrow=(nzvls+1))
zprobval<-dummatz[,2:ncol(dummatz)]
if (modcok==1)
{
zcontval<-matrix(-999,2,ncol(zprobval))
temp<-0
for (i in (1:2))
{
for (j in (1:nrow(dummatz)))
{
if (contvec[i,2]==dummatz[j,1])
{zcontval[i,]<-zprobval[j,];temp<-temp+1}
}
}
if (temp < 2)
{notecode[notes,1]<-20;notes<-notes+1;modcok<-0}
}
if (zmodval[1,1] != 999)
{notecode[notes,1]<-10;notes<-notes+1}
}
}
if ((nxs > 0) & (mcx > 0))
{
tmp<-cbind(rownum,xtmp[,1])
dumtmp<-process.makdummy(tmp,mcx,1,xcatcode)
errcode4<-unlist(dumtmp[5])
errcode5<-unlist(dumtmp[6])
errcode6<-unlist(dumtmp[7])
if (errcode4==1){errcode[errs,1]<-4;errs<-errs+1;criterr<-1}
if (errcode5==1){errcode[errs,1]<-5;errs<-errs+1;criterr<-1}
if (errcode6==1){errcode[errs,1]<-38;errs<-errs+1;criterr<-1}
if (criterr==0)
{
nvls<-unlist(dumtmp[3])
nxvls<-nvls-1
xtmp<-matrix(unlist(dumtmp[1]),ncol=(nxvls+1))
xtmp<-xtmp[,2:ncol(xtmp)];xtmp<-as.data.frame(xtmp)
xcatlab<-c("X1","X2","X3","X4","X5","X6","X7","X8","X9");xcatlab=matrix(xcatlab)
xdich<-as.numeric(nvls==2)
mcxok<-1
dummatx<-matrix(unlist(dumtmp[2]),ncol=(nxvls+1),nrow=(nxvls+1))
xmodvals<-as.matrix(dummatx[,1])
nxpval<-nrow(xmodvals)
}
}
intlab<-matrix(" ",100,1)
for (i in c(1:100)){intlab[i,1]<-paste("Int_",i,sep='')}
bcmat<-matrix(0,needed,needed)
wcmat<-matrix(0,needed,needed)
zcmat<-matrix(0,needed,needed)
wzcmat<-matrix(0,needed,needed)
wsum<-0;zsum<-0;wzsum<-0
}
}
}
#endit
# End A loop reads data and does some other things
# Define model matrices for canned models
if ((criterr==0) & (model != 999))
{
# X->MW, X->MZ, X->MWZ, M->YW, M->YZ, M->YWZ, X->YW, X->YZ, X->YWZ
modelmat<-
matrix(c(1,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,1,1,0,3,0,0,0,0,0,0,1,1,1,4,0,0,0,0,0,0,0,0,0,
5,0,0,0,0,0,0,1,0,0,6,0,0,0,0,0,0,0,0,0,7,1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0,0,0,58,1,0,0,1,0,0,0,0,0,59,1,0,0,1,0,0,1,0,0,60,1,1,0,1,0,0,0,0,0,
61,1,1,0,1,0,0,1,0,0,62,1,1,0,1,0,0,0,1,0,63,1,1,0,1,0,0,1,1,0,64,1,0,0,1,1,0,0,0,0,
65,1,0,0,1,1,0,1,0,0,66,1,0,0,1,1,0,0,1,0,67,1,0,0,1,1,0,1,1,0,68,1,1,1,1,0,0,0,0,0,
69,1,1,1,1,0,0,1,1,1,70,1,0,0,1,1,1,0,0,0,71,1,0,0,1,1,1,1,1,1,72,1,1,1,1,1,1,0,0,0,
73,1,1,1,1,1,1,1,1,1,74,0,0,0,1,0,0,0,0,0,75,1,1,0,1,1,0,0,0,0,76,1,1,0,1,1,0,1,1,0,
77,0,0,0,0,0,0,0,0,0,78,0,0,0,0,0,0,0,0,0,79,0,0,0,0,0,0,0,0,0,80,0,0,0,0,0,0,0,0,0,
81,0,0,0,0,0,0,0,0,0,82,0,0,0,0,0,0,0,0,0,83,1,0,0,0,0,0,0,0,0,84,1,0,0,0,0,0,0,0,0,
85,1,0,0,0,0,0,1,0,0,86,1,0,0,0,0,0,1,0,0,87,0,0,0,1,0,0,0,0,0,88,0,0,0,1,0,0,0,0,0,
89,0,0,0,1,0,0,1,0,0,90,0,0,0,1,0,0,1,0,0,91,0,0,0,0,0,0,0,0,0,92,1,0,0,1,0,0,1,0,0))
dim(modelmat)<-c(10,92);modelmat=t(modelmat);
if (model > 0){tmp<-modelmat[model,2:ncol(modelmat)];tmp=t(matrix(tmp))}
if (model == 0){tmp<-matrix(0,1,9)}
if (model < 4) {bcmat[(nxs+1),1]<-1}
if ((model > 3) & (model != 6))
{bcmat[(nxs+1):(nxs+nms),1]<-onem
bcmat[nrow(bcmat),(nxs+1):(nxs+nms)]<-t(onem)
bcmat[nrow(bcmat),1]<-1}
if ((model==6) | ((model > 82) & (model < 93)))
{
for (j in c(2:nrow(bcmat)))
{for (i in c(1:(j-1)))
{bcmat[j,i]<-1}
}
}
if (model==80)
{for (i in c(1:nms)){bcmat[(nrow(bcmat)-1),i]<-1}}
if (model==81)
{for (j in c(3:nrow(bcmat))){bcmat[j,2]<-1}}
if (model==82)
{bcmat[3,2]<-1;bcmat[5,4]<-1}
if (tmp[1,1]==1)
{
wcmat[(nxs+1):(nxs+nms),1]=onem;wprod<-1;xprod<-1
if ((model==83) | (model==86))
{onemsx<-onem
for (i in c(1:(nms-1))){onemsx[(i+1),1]<-0}
wcmat[(nxs+1):(nxs+nms),1]<-onemsx
}
}
if (tmp[1,4]==1)
{
wcmat[nrow(wcmat),(nxs+1):(nxs+nms)]<-t(onem);wprod<-1;
if ((model==87) | (model==90))
{onemsx<-onem
for (i in c(1:(nms-1))){onemsx[i,1]=0}
wcmat[nrow(wcmat),(nxs+1):(nxs+nms)]=t(onemsx)
}
}
if (tmp[1,7]==1){wcmat[nrow(wcmat),1]<-1;wprod<-1;xprod<-1}
if (tmp[1,2]==1){zcmat[(nxs+1):(nxs+nms),1]<-onem;zprod<-1;xprod<-1}
if (tmp[1,5]==1){zcmat[nrow(zcmat),(nxs+1):(nxs+nms)]=t(onem);zprod<-1}
if (tmp[1,8]==1){zcmat[nrow(zcmat),1]<-1;zprod<-1;xprod<-1}
if (tmp[1,3]==1){wzcmat[(nxs+1):(nxs+nms),1]<-onem;xprod<-1;wprod<-1;zprod<-1}
if (tmp[1,6]==1){wzcmat[nrow(wzcmat),(nxs+1):(nxs+nms)]<-t(onem)}
if (tmp[1,9]==1){wzcmat[nrow(wzcmat),1]<-1;xprod<-1;wprod<-1;zprod<-1}
if ((model==91) | (model==92))
{
for (j in c(1:(nms-1)))
{for (i in c(1:j)){wcmat[(nxs+1+j),(nxs+i)]<-1}
}
}
}
#define and check covariates matrix
if (ncs > 0)
{
ccmat<-matrix(1,(nms+nys),ncs);ccmatoff<-ccmat
if (covmy==1){ccmat[nrow(ccmat),]<-matrix(0,1,ncs)}
if (covmy==2){ccmat[1:nms,]<-matrix(0,nms,ncs)}
if (cmatrix[1,1] != -999)
{if (ncol(cmatrix) != ((nms+nys)*ncs)){errcode[errs,1]<-29;errs<-errs+1;criterr<-1}
if (criterr==0)
{
tmp<-1;for (i in c(1:(nms+nys)))
{
for (j in c(1:ncs))
{ccmat[i,j]<-(1-as.numeric(cmatrix[1,tmp]==0));tmp<-tmp+1}
}
tmpcov<-colSums(ccmat);tmpcov<-as.numeric(tmpcov==0);tmpcov<-sum(tmpcov)
if (tmpcov !=0)
{errcode[errs,1]<-30;errs<-errs+1;criterr<-1}
}
if (covmy != 0){notecode[notes,1]<-1;notes<-notes+1}
}
}
#Define matrices for custom models and do some error checking
if (criterr==0)
{
needed<-needed*(needed-1)/2;nopath<-0
if (bmatrix[1,1] != -999)
{tmp<-1
if ((ncol(bmatrix) != needed) | (sum(bmatrix)==0))
{errcode[errs,1]<-16;errs<-errs+1;criterr<-1} else {
for (i in c(2:nrow(bcmat)))
{for (j in c(1:(i-1)))
{bcmat[i,j]<-(1-as.numeric(bmatrix[1,tmp]==0));tmp<-tmp+1}
}
}
#check to make sure X affects something */
tmpcov<-sum(bcmat[,1])
if ((tmpcov==0) & (criterr==0))
{errcode[errs,1]<-22;errs<-errs+1;criterr<-1}
#check to make sure Y is affected by something */
tmpcov<-sum(bcmat[nrow(bcmat),])
if ((tmpcov==0) & (criterr==0))
{errcode[errs,1]<-23;errs<-errs+1;criterr<-1}
#check for dangling mediators
dm<-0
if (nms > 0)
{
for (i in c(1:nms))
tmpcov<-sum(bcmat[(nxs+i),]);tmpcov2<-sum(bcmat[,(nxs+i)])
{if (((tmpcov==0) | (tmpcov2==0)) & (dm==0) & (criterr==0))
{errcode[errs,1]<-26;errs<-errs+1;criterr<-1;dm<-1}
}
}
}
}
#start b
if (criterr==0)
{
if (wmatrix[1,1] != -999)
{
tmp<-1
if (ncol(wmatrix) != needed)
{errcode[errs,1]<-17;errs<-errs+1;criterr<-1} else {
modelvar[1,1]="CUSTOM"
for (i in (2:nrow(wcmat)))
{
for (j in (1:(i-1)))
{wcmat[i,j]<-(1-as.numeric(wmatrix[1,tmp]==0))
#dont allow to specify moderation of a path that doesnt exist
if ((wcmat[i,j]==1) & (bcmat[i,j]==0) & (nopath==0))
{errcode[errs,1]<-20;errs<-errs+1;criterr<-1;nopath<-1}
tmp<-tmp+1
}
}
}
}
if (zmatrix[1,1] != -999)
{
tmp<-1
if (ncol(zmatrix) != needed)
{errcode[errs,1]<-18;errs<-errs+1;criterr<-1} else {
modelvar[1,1]="CUSTOM"
if ((sum(wcmat)==0) & (model==999))
{errcode[errs,1]<-21;errs<-errs+1;criterr<-1}
for (i in (2:nrow(zcmat)))
{
for (j in (1:(i-1)))
{zcmat[i,j]<-(1-as.numeric(zmatrix[1,tmp]==0))
#dont allow to specify moderation of a path that doesnt exist
if ((zcmat[i,j]==1) & (bcmat[i,j]==0) & (nopath==0))
{errcode[errs,1]<-20;errs<-errs+1;criterr<-1;nopath<-1}
tmp<-tmp+1
}
}
}
}
tmp<-1
if (wzmatrix[1,1] != -999)
{
if (ncol(wzmatrix) != needed)
{errcode[errs,1]<-19;errs<-errs+1;criterr<-1}
modelvar[1,1]="CUSTOM"
}
if (criterr==0)
{
for (i in (2:nrow(wzcmat)))
{
for (j in (1:(i-1)))
{
#set corresponding elements in W and Z for three way interaction
if (wzmatrix[1,1] != -999){wzcmat[i,j]<-(1-as.numeric(wzmatrix[1,tmp]==0))}
if (wzcmat[i,j]==1){wcmat[i,j]<-1;zcmat[i,j]<-1}
#dont allow to specify moderation of a path that doesnt exist
if ((wzcmat[i,j]==1) & (bcmat[i,j]==0) & (nopath==0))
{errcode[errs,1]<-20;errs<-errs+1;criterr<-1;nopath<-1}
tmp<-tmp+1
}
}
}
}
# end B
if (criterr==0)
{
xprod<-(sum(wcmat[,1])+sum(zcmat[,1])+sum(wzcmat[,1]))
xprod<-as.numeric(xprod > 0)
wsum<-sum(wcmat)
wprod<-as.numeric(wsum > 0)
if (nms > 0)
{
for (i in c(1:nms))
{
tmp<-(sum(wcmat[,(1+i)])+sum(zcmat[,(1+i)])+sum(wzcmat[,(1+i)]))
mprod[1,i]<-as.numeric(tmp>0)
}
}
if ((wsum > 0) & (w=="xxxxx")){errcode[errs,1]<-11;errs<-errs+1;criterr<-1}
if ((wsum==0) & (w != "xxxxx")){errcode[errs,1]<-10;errs<-errs+1;criterr<-1}
zsum<-sum(zcmat)
zprod<-as.numeric(zsum > 0)
if ((zsum > 0) & (z=="xxxxx")){errcode[errs,1]<-13;errs<-errs+1;criterr<-1}
if ((zsum==0) & (z != "xxxxx")){errcode[errs,1]<-12;errs<-errs+1;criterr<-1}
if ((zsum > 0) & (wsum==0)){errcode[errs,1]<-35;errs<-errs+1;criterr<-1}
}
if ((criterr==0) & (nms > 1))
{
serchk<-bcmat[2:(nrow(bcmat)-1),2:ncol(bcmat)]
if (sum(serchk) > 0)
{serial<-1
if (nms > 6){errcode[errs,1]<-36;errs<-errs+1;criterr<-1}
}
}
#mean center if needed
if ((center > 0) & (criterr==0))
{
centvar<-matrix(c(" "))
if (criterr==0)
{
if ((center==1) | ((center==2) & (wdich==0)))
{
if ((wprod==1) & (mcwok==0) & (nwpval > 0))
{
for (i in c(1:nws))
{
wtmp[,i]<-wtmp[,i]-(sum(wtmp[,i])/n)
centvar<-cbind(centvar,wnames[1,i])
}
desctmp2<-process.describ3(wtmp,wmodcust,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
wmin<-desctmp[3,1];wmax<-desctmp[4,1]
if (wmodcust==0)
{modvals<-matrix(unlist(desctmp2[2]))
wmodvals<-modvals;wprobval<-wmodvals}
}
}
if ((center==1) | ((center==2) & (zdich==0)))
{
if ((zprod==1) & (mczok==0) & (nzpval > 0))
{
for (i in c(1:nzs))
{
ztmp[,i]<-ztmp[,i]-(sum(ztmp[,i])/n)
centvar<-cbind(centvar,znames[1,i])
}
desctmp2<-process.describ3(ztmp,zmodcust,quantile)
desctmp<-matrix(unlist(desctmp2[1]))
zmin<-desctmp[3,1];zmax<-desctmp[4,1]
if (zmodcust==0)
{modvals<-matrix(unlist(desctmp2[2]))
zmodvals<-modvals;zprobval<-zmodvals}
}
}
if ((center==1) | ((center==2) & (xdich==0)))
{
if ((xprod==1) & (mcxok==0))
{
for (i in c(1:nxs))
{
xtmp[,i]<-xtmp[,i]-(sum(xtmp[,i])/n)
centvar<-cbind(centvar,xnames[1,i])
}
desctmp2<-process.describ3(xtmp,0,quantile)
modvals<-matrix(unlist(desctmp2[2]))
xmodvals<-modvals;xprobval<-as.matrix(xmodvals)
}
}
if (nms > 0)
{
for (i in c(1:nms))
{
if (mprod[1,i]==1)
{
mtmp[,i]<-mtmp[,i]-(sum(mtmp[,i])/n)
centvar<-cbind(centvar,mnames[i,1])
}
}
desctmp2<-process.describ3(mtmp,0,quantile)
desct12<-matrix(unlist(desctmp2[1]),ncol=ncol(mtmp))
if ((cdeval[1,1]==-999) & (model==74))
{medmeans<-t(matrix(desct12[1,]))}
modvals<-matrix(unlist(desctmp2[2]),ncol=ncol(mtmp))
mmodvals<-modvals;mprobval<-mmodvals;
}
}
if (ncol(centvar) > 1)
{notecode[notes,1]<-3;notes<-notes+1}
}
# Start D
#CONSTRUCT THE DATA MATRICES FOR EACH OF THE MODELS
if (criterr==0)
{
# The i loop is the dependent variable in the model matrices
# The j loop is the predictor variables in the model matrices
wsum<-sum(wcmat);zsum<-sum(zcmat);wzsum<-sum(wzcmat)
nump<-matrix(-999,1,(nys+nms));numint<-matrix(0,1,(nys+nms))
#DV
datcount<-1;
xtmpuse<-0;wtmpuse<-0;ztmpuse<-0;xwtmpus<-0;xztmpus<-0;wztmpus<-0;xwztmpu<-0;
xtmploc<- matrix(-999);wtmploc<- -999;xwtmplo<- -999;ztmploc<- -999
xztmplo<- -999;wztmplo<- -999;xwztmplo<- -999
vlabs<-" "
if (ncs > 0){ctmpuse<-matrix(0,1,ncs)}
if (nms > 0)
{
mtmpuse<-matrix(0,1,nms)
mwtmpus<-matrix(0,1,nms)
mztmpus<-matrix(0,1,nms)
mwztmpu<-matrix(0,1,nms)
mtmploc<-matrix(0,1,nms)
mwtmplo<-matrix(-999,nwvls,nms)
mztmplo<-matrix(-999,nzvls,nms)
mwztmplo<-matrix(-999,(nwvls*nzvls),nms)
}
if (ncs > 0){ctmploc<-matrix(0,1,ncs)}
fulldat<-matrix(1,n,1)
datindx<-matrix(-999,1000,(nms+nys))
wherew<-matrix(-999,2,(nms+nys));wherex<-matrix(-999,2,(nms+nys))
wherez<-matrix(-999,2,(nms+nys));wherexw<-matrix(-999,2,(nms+nys))
wherexz<-matrix(-999,2,(nms+nys));wherewz<-matrix(-999,2,(nms+nys))
wherexwz<-matrix(-999,2,(nms+nys))
if (nms > 0)
{
wherem<-matrix(-999,nms,(nms+nys))
wheremw<-matrix(-999,(nms*2),(nms+nys))
wheremz<-matrix(-999,(nms*2),(nms+nys))
wheremwz<-matrix(-999,(nms*2),(nms+nys))
}
wzhigh<-matrix(0,1000,(((nms+1)*(nms+2))/2))
whigh<-matrix(0,1000,(((nms+1)*(nms+2))/2))
zhigh<-matrix(0,1000,(((nms+1)*(nms+2))/2))
fochigh<-matrix(0,1000,(((nms+1)*(nms+2))/2))
xcoefloc<-matrix(c(1,2,3,4,5,6,7,8,9))
intkey<-t(matrix(c(" ", " ", " ", " ", " ", " ", " ")))
wzhighct<-0;whighct<-0;zhighct<-0;foccnt<-0
if (nms > 0){mnames<-t(mnames)}
if (ncs > 0){covnames<-t(covnames)}
xtmp<-data.matrix(xtmp)
#START DV LOOP
for (i in (2:nrow(bcmat)))
{
wdid<-0;zdid<-0;wzdid<-0;cntmp<-1;start<-1;
if (i < nrow(bcmat))
{outv<-mtmp[,(i-1)]
modlabel<-matrix(c(mnames[1,(i-1)],"constant"))}
if (i==nrow(bcmat))
{outv<-ytmp;modlabel<-matrix(c(ynames,"constant"))}
# The j loop is the mediator
# START MED
for (j in (1:(i-1)))
{
foccnt<-foccnt+1
if ((j==1) & (bcmat[i,j]==1))
{
outv<-cbind(outv,xtmp)
modlabel<-matrix(c(modlabel,xcatlab[1:nxvls,1]))
if (xtmpuse==0)
{
fulldat<-matrix(c(fulldat,xtmp),nrow=n)
xtmpuse<-1
for (k4 in (datcount:(datcount+(nxvls-1))))
{xtmploc<-matrix(c(xtmploc,k4))}
xtmploc<-matrix(xtmploc[2:nrow(xtmploc),1])
datcount<-datcount+nxvls
}
datindx[start:(start+nrow(xtmploc)-1),(i-1)]<-xtmploc
wherex[1,(i-1)]<-start+1
wherex[2,(i-1)]<-start+nrow(xtmploc)-1+1
#do if (model = 74)
#end if
onebl<-matrix(1,nrow(xtmploc),1)
fochigh[(start+1):(start+nrow(xtmploc)),foccnt]<-onebl
start<-start+nrow(xtmploc)
}
if ((j > 1) & (bcmat[i,j]==1))
{
outv<-cbind(outv,mtmp[,(j-1)])
modlabel<-matrix(c(modlabel,mnames[1,(j-1)]))
if (mtmpuse[1,(j-1)]==0)
{
fulldat<-matrix(c(fulldat,mtmp[,(j-1)]),nrow=n)
mtmpuse[1,(j-1)]<-1
mtmploc[1,(j-1)]<-datcount
datcount<-datcount+1
}
datindx[start:(start+nrow(mtmploc)-1),(i-1)]<-mtmploc[1,(j-1)]
wherem[(j-1),(i-1)]<-start+1
#onebl<-matrix(1,(nrow(mtmploc[1,(j-1)])),1)
#onebl<-matrix(1,mtmploc[1,(j-1)],1)
onebl<-1
#ttt<-nrow(mtmploc[1,(j-1)])+start-1
#fochigh[(start+1):(start+nrow(mtmploc[1,(j-1)])),foccnt]<-onebl
#fochigh[(start+1):(start+mtmploc[1,(j-1)]),foccnt]<-onebl
fochigh[(start+1):(start+1),foccnt]<-onebl
#start<-start+mtmploc[1,(j-1)]
start<-start+1
}
}
#END MED
#START W
if (wsum > 0)
wtmp<-data.matrix(wtmp)
{
for (j in c(1:(i-1)))
{
whighct<-whighct+1
if ((j==1) & (wcmat[i,j]==1))
{
if (wdid==0)
{
outv<-cbind(outv,wtmp)
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,wcatlab[1:nwvls,1]))
wdid<-1
if (wtmpuse==0)
{
fulldat<-matrix(c(fulldat,wtmp),nrow=n)
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
wtmpuse<-1
for (k4 in (datcount:(datcount+(nwvls-1))))
{wtmploc<-matrix(c(wtmploc,k4))}
wtmploc<-matrix(wtmploc[2:nrow(wtmploc),1])
datcount<-datcount+nwvls
}
}
datindx[start:(start+nrow(wtmploc)-1),(i-1)]<-wtmploc
wherew[1,(i-1)]<-start+1
wherew[2,(i-1)]<-start+nrow(wtmploc)-1+1
start<-start+nrow(wtmploc)
for (k1 in c(1:nxvls))
{
for (k2 in c(1:nwvls))
{
outv<-as.matrix(cbind(outv,(xtmp[,k1]*wtmp[,k2])))
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",xcatlab[k1,1],"x",wcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
if (xwtmpus==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nxvls*nwvls)+1):ncol(outv)]),nrow=n)
xwtmpus<-1
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
for (k4 in (datcount:(datcount+((nwvls*nxvls)-1))))
{xwtmplo<-matrix(c(xwtmplo,k4))}
xwtmplo<-matrix(xwtmplo[2:nrow(xwtmplo),1])
datcount<-datcount+(nxvls*nwvls)
}
datindx[start:(start+nrow(xwtmplo)-1),(i-1)]<-xwtmplo
wherexw[1,(i-1)]<-start+1
wherexw[2,(i-1)]<-start+nrow(xwtmplo)-1+1
onebl<-matrix(1,nrow(xwtmplo),1)
whigh[(start+1):(start+nrow(xwtmplo)),whighct]<-onebl
start<-start+nrow(xwtmplo)
}
if ((j > 1) & (wcmat[i,j]==1))
{
if ((wdid==0) & (model != 74))
{
outv<-cbind(outv,wtmp)
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,wcatlab[1:nwvls,1]))
wdid<-1
if (wtmpuse==0)
{
fulldat<-matrix(c(fulldat,wtmp),nrow=n)
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
wtmpuse<-1
for (k4 in (datcount:(datcount+(nwvls-1))))
{wtmploc<-matrix(c(wtmploc,k4))}
wtmploc<-matrix(wtmploc[2:nrow(wtmploc),1])
datcount<-datcount+nwvls
}
datindx[start:(start+nrow(wtmploc)-1),(i-1)]<-wtmploc
wherew[1,(i-1)]<-start+1
wherew[2,(i-1)]<-start+nrow(wtmploc)-1+1
start<-start+nrow(wtmploc)
}
for (k2 in c(1:nwvls))
{
outv<-as.matrix(cbind(outv,(mtmp[,(j-1)]*wtmp[,k2])))
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",mnames[1,(j-1)],"x",wcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
if (mwtmpus[1,(j-1)]==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-nwvls+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
mwtmpus[1,(j-1)]<-1
mw22<- -999
for (k4 in (datcount:(datcount+(nwvls-1))))
{mw22<-matrix(c(mw22,k4))}
mwtmplo[,(j-1)]=matrix(mw22[2:nrow(mw22),1])
datcount<-datcount+nwvls
}
datindx[start:(start+nrow(mwtmplo)-1),(i-1)]<-mwtmplo[,(j-1)]
wheremw[((2*j)-3),(i-1)]<-start+1
wheremw[((2*j)-2),(i-1)]<-start+nrow(mwtmplo)-1+1
onebl<-matrix(1,nrow(mwtmplo),1)
whigh[(start+1):(start+nrow(mwtmplo)),whighct]<-onebl
start<-start+nrow(mwtmplo)
}
}
}
#END W
#START Z
if (zsum > 0)
ztmp<-data.matrix(ztmp)
{
for (j in c(1:(i-1)))
{
zhighct<-zhighct+1
if ((j==1) & (zcmat[i,j]==1))
{
if (zdid==0)
{
outv<-cbind(outv,ztmp)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
modlabel<-matrix(c(modlabel,zcatlab[1:nzvls,1]))
zdid<-1
if (ztmpuse==0)
{
fulldat<-matrix(c(fulldat,ztmp),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
ztmpuse<-1
for (k4 in (datcount:(datcount+(nzvls-1))))
{ztmploc<-matrix(c(ztmploc,k4))}
ztmploc<-matrix(ztmploc[2:nrow(ztmploc),1])
datcount<-datcount+nzvls
}
}
datindx[start:(start+nrow(ztmploc)-1),(i-1)]<-ztmploc
wherez[1,(i-1)]<-start+1
wherez[2,(i-1)]<-start+nrow(ztmploc)-1+1
start<-start+nrow(ztmploc)
for (k1 in c(1:nxvls))
{for (k2 in c(1:nzvls))
{
outv=as.matrix(cbind(outv,(xtmp[,k1]*ztmp[,k2])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",xcatlab[k1,1],"x",zcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
if (xztmpus==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nxvls*nzvls)+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
xztmpus<-1
for (k4 in (datcount:(datcount+((nzvls*nxvls)-1)))){xztmplo<-matrix(c(xztmplo,k4))}
xztmplo<-matrix(xztmplo[2:nrow(xztmplo),1])
datcount<-datcount+(nxvls*nzvls)
}
datindx[start:(start+nrow(xztmplo)-1),(i-1)]<-xztmplo
wherexz[1,(i-1)]<-start+1
wherexz[2,(i-1)]<-start+nrow(xztmplo)-1+1
onebl<-matrix(1,nrow(xztmplo),1)
zhigh[(start+1):(start+nrow(xztmplo)),zhighct]<-onebl
start<-start+nrow(xztmplo)
}
if ((j > 1) & (zcmat[i,j]==1))
{
if (zdid==0)
{
outv<-cbind(outv,ztmp)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
modlabel<-matrix(c(modlabel,zcatlab[1:nzvls,1]))
zdid<-1
if (ztmpuse==0)
{
fulldat<-matrix(c(fulldat,ztmp),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
ztmpuse<-1
for (k4 in (datcount:(datcount+(nzvls-1))))
{ztmploc<-matrix(c(ztmploc,k4))}
ztmploc<-matrix(ztmploc[2:nrow(ztmploc),1])
datcount<-datcount+nzvls
}
datindx[start:(start+nrow(ztmploc)-1),(i-1)]<-ztmploc
wherez[1,(i-1)]<-start+1
wherez[2,(i-1)]<-start+nrow(ztmploc)-1+1
start<-start+nrow(ztmploc)
}
for (k2 in (1:nzvls))
{
outv=as.matrix(cbind(outv,(mtmp[,(j-1)]*ztmp[,k2])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":", mnames[1,(j-1)],"x",zcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
if (mztmpus[1,(j-1)]==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-nzvls+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
mztmpus[1,(j-1)]<-1
mz22<- -999
for (k4 in (datcount:(datcount+(nzvls-1)))){mz22<-matrix(c(mz22,k4))}
mztmplo[,(j-1)]<-matrix(mz22[2:nrow(mz22),1])
datcount<-datcount+nzvls
}
datindx[start:(start+nrow(mztmplo)-1),(i-1)]<-mztmplo[,(j-1)]
wheremz[((2*j)-3),(i-1)]<-start+1
wheremz[((2*j)-2),(i-1)]<-start+nrow(mztmplo)-1+1
onebl<-matrix(1,nrow(mztmplo),1)
zhigh[(start+1):(start+nrow(mztmplo)),zhighct]<-onebl
start<-start+nrow(mztmplo)
}
}
}
#END Z
#START WZ
if (wzsum > 0)
{
for (j in (1:(i-1)))
{
wzhighct<-wzhighct+1
if ((j==1) & (wzcmat[i,j]==1))
{
if (wzdid==0)
{
for (k1 in (1:nwvls))
{
for (k2 in (1:nzvls))
{
outv<-as.matrix(cbind(outv,(wtmp[,k1]*ztmp[,k2])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",wcatlab[k1,1],"x",zcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
if (wztmpus==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nwvls*nzvls)+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
wztmpus<-1
for (k4 in (datcount:(datcount+((nwvls*nzvls)-1))))
{wztmplo<-matrix(c(wztmplo,k4))}
wztmplo<-matrix(wztmplo[2:nrow(wztmplo),1])
datcount<-datcount+(nzvls*nwvls)
}
wzdid<-1
}
datindx[start:(start+nrow(wztmplo)-1),(i-1)]<-wztmplo
wherewz[1,(i-1)]<-start+1
wherewz[2,(i-1)]<-start+nrow(wztmplo)-1+1
start<-start+nrow(wztmplo)
for (k1 in (1:nxvls))
{
for (k2 in (1:nwvls))
{
for (k3 in (1:nzvls))
{
outv<-as.matrix(cbind(outv,(xtmp[,k1]*wtmp[,k2]*ztmp[,k3])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff((i-1),wiscov)<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",xcatlab[k1,1],"x",wcatlab[k2,1],"x",zcatlab[k3,1]),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
}
if (xwztmpu==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nxvls*nwvls*nzvls)+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff((i-1),wiscov)<-0}
xwztmpu<-1
for (k4 in (datcount:(datcount+((nzvls*nxvls*nwvls)-1))))
{xwztmplo<-matrix(c(xwztmplo,k4))}
xwztmplo<-matrix(xwztmplo[2:nrow(xwztmplo),1])
datcount<-datcount+(nxvls*nzvls*nwvls)
}
datindx[start:(start+nrow(xwztmplo)-1),(i-1)]<-xwztmplo
wherexwz[1,(i-1)]<-start+1
wherexwz[2,(i-1)]<-start+nrow(xwztmplo)-1+1
onebl<-matrix(1,nrow(xwztmplo),1)
wzhigh[(start+1):(start+nrow(xwztmplo)),wzhighct]<-onebl
start<-start+nrow(xwztmplo)
}
if ((j > 1) & (wzcmat[i,j]==1))
{
if (wzdid==0)
{
for (k1 in (1:nwvls))
{
for (k2 in (1:nzvls))
{
outv<-as.matrix(cbind(outv,(wtmp[,k1]*ztmp[,k2])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",wcatlab[k1,1],"x",zcatlab[k2,1]," "," "),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
if (wztmpus==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nwvls*nzvls)+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
wztmpus<-1
for (k4 in (datcount:(datcount+((nwvls*nzvls)-1))))
{wztmplo<-matrix(c(wztmplo,k4))}
wztmplo<-matrix(wztmplo[2:nrow(wztmplo),1])
datcount<-datcount+(nzvls*nwvls)
}
wzdid<-1
datindx[start:(start+nrow(wztmplo)-1),(i-1)]<-wztmplo
wherewz[1,(i-1)]<-start+1
wherewz[2,(i-1)]<-start+nrow(wztmplo)-1+1
start<-start+nrow(wztmplo)
}
for (k1 in (1:nwvls))
{
for (k2 in (1:nzvls))
{
outv<-as.matrix(cbind(outv,(mtmp[,(j-1)]*wtmp[,k1]*ztmp[,k2])))
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
modlabel<-matrix(c(modlabel,intlab[cntmp,1]))
intkeyt<-matrix(c(intlab[cntmp,1],":",mnames[1,(j-1)],"x",wcatlab[k1,1],"x",zcatlab[k2,1]),ncol=7)
intkey<-rbind(intkey,intkeyt)
cntmp<-cntmp+1
}
}
if (mwztmpu[1,(j-1)]==0)
{
fulldat<-matrix(c(fulldat,outv[,(ncol(outv)-(nwvls*nzvls)+1):ncol(outv)]),nrow=n)
if ((ncs > 0) & (ziscov > 0)){ccmatoff[(i-1),ziscov]<-0}
if ((ncs > 0) & (wiscov > 0)){ccmatoff[(i-1),wiscov]<-0}
mwztmpu[1,(j-1)]<-1
mz22<- -999
for (k4 in (datcount:(datcount+(nwvls*nzvls)-1)))
{mz22<-matrix(c(mz22,k4))}
mwztmplo[,(j-1)]<-matrix(mz22[2:nrow(mz22),1])
datcount<-datcount+(nwvls*nzvls)
}
datindx[start:(start+nrow(mwztmplo)-1),(i-1)]<-mwztmplo[,(j-1)]
wheremwz[((2*j)-3),(i-1)]<-start+1
wheremwz[((2*j)-2),(i-1)]<-start+nrow(mwztmplo)-1+1
onebl<-matrix(1,nrow(mwztmplo),1)
wzhigh[(start+1):(start+nrow(mwztmplo)),wzhighct]<-onebl
start<-start+nrow(mwztmplo)
}
}
}
#END WZ
#START COV
if (ncs > 0)
{
ccmat<-ccmat*ccmatoff
for (j in c(1:ncs))
{
if (ccmat[(i-1),j]==1)
{
if (j==wiscov){ctmp[,j]<-wtmp}
if (j==ziscov){ctmp[,j]<-ztmp}
outv<-cbind(outv,ctmp[,j])
modlabel<-matrix(c(modlabel,covnames[1,j]))
if (ctmpuse[1,j]==0)
{
fulldat<-matrix(c(fulldat,ctmp[,j]),nrow=n)
ctmpuse[1,j]<-1
ctmploc[1,j]<-datcount
datcount<-datcount+1
}
datindx[start:(start+nrow(ctmploc)-1),(i-1)]<-ctmploc[1,j]
start<-start+1
}
}
}
#END COV
wdid<-0;zdid<-0;wzdid<-0
vlabs<-matrix(c(vlabs,modlabel[2:nrow(modlabel),1]))
numint[1,(i-1)]<-cntmp-1
nump[1,(i-1)]<-nrow(modlabel)-1
}
#END DV LOOP
if ((modcok==1) & ((nms > 0) | (zcmat[2,1] != 1) | (mcx != 0)))
{notecode[notes,1]<-19;notes<-notes + 1;modcok<-0}
if (((serial==1) | (sum(numint)>0) | (nms==0)) & (mc > 0))
{notecode[notes,1]<-15;notes<-notes+1;boot<-mc;mc<-0}
if ((boot != 0) | (mc != 0))
{
bootsz<-boot
if (mc > 0){bootsz<-mc;saveboot<-0}
cilow<-0;cihigh<-bootsz+1
while ((cilow <=0) | (cihigh > bootsz))
{
cilow<-round(bootsz*(1-(conf/100))/2)
cihigh<-trunc((bootsz*(conf/100)+(bootsz*(1-(conf/100))/2)))+1
if ((cilow < 1) | (cihigh > bootsz))
{bootsz<-trunc((bootsz+1000)/1000)*1000;adjust<-1}
}
if (boot > 0){boot<-bootsz}
if (mc > 0){mc<-bootsz}
if ((adjust==1) & (boot > 0)){notecode[notes,1]<-8;notes<-notes+1}
if ((adjust==1) & (mc > 0)){notecode[notes,1]<-16;notes<-notes+1}
}
maxboot<-trunc(2*boot)
if (maxboots > maxboot){maxboot<-trunc(maxboots)}
#insert seed here
if ((seed==-999) & (boot > 0) | (mc > 0))
{seed<-trunc(runif(1,1,1000000));set.seed(seed);ranseed<-1}
if (sum(numint) > 0){intkey<-matrix(intkey[2:nrow(intkey),],ncol=7)}
vlabs<-matrix(vlabs[2:nrow(vlabs),1])
fulldat<-as.data.frame(fulldat[,2:ncol(fulldat)])
fulldat<-data.matrix(fulldat)
fochigh<-fochigh[1:max(nump),]
whigh<-as.matrix(whigh[1:max(nump),])
zhigh<-as.matrix(zhigh[1:max(nump),])
wzhigh<-as.matrix(wzhigh[1:max(nump),])
coeffs<-fochigh+whigh+zhigh+wzhigh
bootloc<-matrix(0,max(nump),ncol(nump))
#Here is am deriving the locations in bootfile needed for indirect effects
if (nms > 0)
{
cntmp<-1
for (i in (1:ncol(nump)))
{for (j in (1:nump[1,i]))
{bootloc[j,i]<-cntmp;cntmp<-cntmp+1}
}
fochighb<-matrix(0,nrow(fochigh),ncol(fochigh))
whighb<-fochighb
zhighb<-fochighb
wzhighb<-fochighb
thetaxmb<-matrix(0,nrow(fochighb),nms)
thetaxyb<-matrix(0,nrow(fochighb),1)
pathsfoc<-matrix(0,nxvls,1)
cntmp<-1
for (i in (1:(nms+nys)))
{
for (j in (1:i))
{
fochighb[,cntmp]<-(fochigh[,cntmp]*bootloc[,i])
whighb[,cntmp]<-(whigh[,cntmp]*bootloc[,i])
zhighb[,cntmp]<-(zhigh[,cntmp]*bootloc[,i])
wzhighb[,cntmp]<-(wzhigh[,cntmp]*bootloc[,i])
coeffsb<-(fochighb+whighb+zhighb+wzhighb)
if ((i < (nms+nys)) & (j==1)){thetaxmb[,i]<-coeffsb[,cntmp]}
if ((i==(nms+nys)) & (j==1)){thetaxyb[,1]<-coeffsb[,cntmp]}
cntmp<-cntmp+1
}
}
thetamyb<-as.matrix(coeffsb[,(ncol(coeffsb)-nms+1):ncol(coeffsb)])
if (serial==1)
{thetammb<-matrix(0,nrow(coeffsb),((nms*(nms-1))/2))}
cntmp<-1
if ((nms > 1) & (serial==1))
{
for (i in (1:(nms-1)))
{
start<-((i+2)*(i+1))/2
for (j in (2:(nms-i+1)))
{
thetammb[,cntmp]<-coeffsb[,start]
start<-start+j+i-1
cntmp<-cntmp+1
}
}
}
}
if ((total==1) & ((sum(numint)==0) | (xmint==1)))
{
dototal<-1
if ((sum(bcmat[,1]) != (nms+nys)) | (sum(bcmat[nrow(bcmat),]) != (nms+nys)))
{dototal<-0;alttotal<-1;notecode[notes,1]<-12;notes<-notes+1}
if (ncs > 0)
{
if ((sum(ccmat)) < (nrow(ccmat)*ncol(ccmat)))
{dototal<-0;alttotal<-1;notecode[notes,1]<-11;notes<-notes+1}
}
if (model==74)
{
if ((xdich==0) & (nxvls==1))
{dototal<-0;alttotal<-1}
if (((xdich==1) | (nxvls > 1)) & (ncs > 0) & (model==74))
{dototal<-0;alttotal<-1}
}
}
}
# End D
if ((criterr==0) & (ncs > 0))
{
tmperr<-sum(as.numeric(colSums(ccmat)==0))
if (sum(tmperr)!=0)
{errcode[errs,1]<-51;errs<-errs+1;criterr<-1}
}
if (outscreen==1)
{
cat("\n")
cat("******************** PROCESS for R Version 4.2 beta **************** \n \n")
cat(" Written by Andrew F. Hayes, Ph.D. www.afhayes.com \n")
cat(" Documentation available in Hayes (2022). www.guilford.com/p/hayes3 \n \n")
}
if (criterr==0)
{
if ((stand==1) & (ydich==1)){stand<-0}
anymod2<-sum(wcmat+zcmat+wzcmat)
if ((anymod2 > 0) & (stand==1))
{notecode[notes,1]<-27;notes<-notes+1;stand<-0}
rownames(modelvar)<-modelvlb
colnames(modelvar)<-" "
funny<-1
if (outscreen==1)
{
cat("*********************************************************************** \n")
print(noquote(modelvar))
cat("\n")
if (ncs > 0)
{
cat("Covariates: \n")
covname2<-c(" ", covnames)
covname2<-t(noquote(covname2))
write.table(covname2,quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
}
cat("Sample size: ")
write.table(n,quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
if (seed != -999)
{if (ranseed==0)
{cat("Custom seed: ")}
if (ranseed==1)
{cat("Random seed: ")}
write.table(seed,quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
}
maxresm<-9;
resultm<-matrix(99999,1,maxresm)
if (describe==1)
{
means=apply(dat,2,mean);sdvec=apply(dat,2,sd);corall=cor(dat);
means<-rbind(t(matrix(means)),t(matrix(sdvec)))
means2<-noquote(matrix(sprintf(decimals,means),nrow=nrow(means)))
corall2<-noquote(matrix(sprintf(decimals,corall),nrow=nrow(corall)))
if (ncol(means) > 9)
{resultm<-matrix(99999,1,ncol(means));maxresm<-ncol(means)}
resultm2<-matrix(99999,2,maxresm)
resultm2[1:2,1:ncol(means)]<-means
resultm<-rbind(resultm,resultm2)
resultm2<-matrix(99999,ncol(corall),maxresm)
resultm2[1:ncol(corall),1:ncol(corall)]<-corall
resultm<-rbind(resultm,resultm2)
colnames(means2)<-varnames
colnames(corall2)<-varnames
rownames(corall2)<-varnames
rownames(means2)<-matrix(c("Mean","SD"))
if (outscreen==1)
{
cat("Variable means and standard deviations:\n")
print(means2,right=T)
cat("\n")
cat("Variable intercorrelations (Pearson's r):\n")
print(corall2,right=T)
}
}
#resultm2<-matrix(99999,nrow(corall),maxresm)
#resultm2[1:nrow(corall),1:ncol(corall)]<-corall
#resultm<-rbind(resultm,resultm2)
if (mcxok==1)
{cat("Coding of categorical X variable for analysis: \n")
dummatx2<-noquote(matrix(sprintf(decimals,dummatx),nrow=nrow(dummatx)))
colnames(dummatx2)<-c(xnames,xcatlab[1:nxvls,1])
rownames(dummatx2)<-t(matrix(replicate((nxvls+1)," ")))
print(dummatx2,right=T)}
if ((mcwok==1) & (xmint==0))
{cat("Coding of categorical W variable for analysis: \n")
dummatw2<-noquote(matrix(sprintf(decimals,dummatw),nrow=nrow(dummatw)))
colnames(dummatw2)<-c(wnames,t(wcatlab[1:nwvls,1]))
rownames(dummatw2)<-t(matrix(replicate((nwvls+1)," ")))
print(dummatw2,right=T)}
if (mczok==1)
{cat("Coding of categorical Z variable for analysis: \n")
dummatz2<-noquote(matrix(sprintf(decimals,dummatz),nrow=nrow(dummatz)))
colnames(dummatz2)<-c(znames,t(zcatlab[1:nzvls,1]))
rownames(dummatz2)<-t(matrix(replicate((nzvls+1)," ")))
print(dummatz2,right=T)}
}
}
#START cycle through the models
if (criterr==0)
{
outnames<-ynames
outvars<-ytmp
if (nms > 0)
{
outnames<-matrix(c(mnames,ynames))
outvars<-cbind(mtmp,ytmp)
indcov<-matrix(0,((nms*2)+(nms*(nxvls-1))),((nms*2)+(nms*(nxvls-1))))
mcsopath<-matrix(0,((nms*2)+(nms*(nxvls-1))),1)
}
labstart<-1
intstart<-1
start<-1
coeffmat<-matrix(0,1,6)
conseq<-" "
dfmat<-0;coeffcol<-0;pathscnt<-1;pathscn2<-1
# START G LOOP
for (i in c(1:(nms+nys)))
{
if (outscreen==1)
{cat("\n*********************************************************************** \n")}
highf<-matrix(0,1,5);highf2<-highf
if ((i==(nms+nys)) & (ydich==1)){highf=matrix(0,1,3);highf2<-highf}
flabel<-" "
y<-outvars[,i]
xindx<-datindx[1:(nump[1,i]-1),i]
x<-fulldat[,xindx]
x<-cbind(ones,x)
xsq<-t(x)%*%x
exsq<-eigen(xsq)
exsq<-matrix(unlist(exsq[1]))
zeroeig<-sum(as.numeric(exsq <= 0.000000000002))
if (outscreen==1)
{
cat("Outcome Variable: ")
write.table(outnames[i,1],quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
if ((ydich==1) & (i==(nms+nys)))
{
cat("Coding of binary Y for logistic regression analysis:\n")
rcd<-noquote(matrix(sprintf(decimals,rcd),nrow=nrow(rcd)))
colnames(rcd)<-c(outnames[i,1], "Analysis")
rownames(rcd)<-t(matrix(replicate(nrow(rcd)," ")))
print(rcd,right=T)
cat("\n")
}
}
if (zeroeig > 0)
{
cat("\nSINGULAR OR NEAR SINGULAR DATA MATRIX.\n")
criterr<-1;errcode[errs,1]<-31;errs<-errs+1;
}
means<-colSums(x)/n
vlabsm<-matrix(vlabs[labstart:(labstart+(nump[1,i]-1)),1])
#START E
if (criterr==0)
{
if ((ydich==0) | (i < (nms+nys)))
{
modoutz<-process.modelest(y,x,1,1,xp2,hc)
modres<-matrix(unlist(modoutz[1]),nrow=nump[1,i])
direff<-matrix(modres,nrow=ncol(x))
#modresl<-matrix(unlist(modoutz[2]))
modsum<-matrix(unlist(modoutz[3]))
tval<-matrix(unlist(modoutz[7]))
resid<-matrix(unlist(modoutz[8]))
modresid<-cbind(modresid,resid)
brsq2<-modsum[2,1]
dfres<-modsum[6,1]
#for recording results
resultm2<-matrix(99999,1,maxresm)
resultm2[1,1:nrow(modsum)]<-t(modsum)
resultm<-rbind(resultm,resultm2)
resultm2<-matrix(99999,nrow(modres),maxresm)
resultm2[1:nrow(modres),1:ncol(modres)]<-modres
resultm<-rbind(resultm,resultm2)
#end recording results
modrest9<-modres
modres<-noquote(matrix(sprintf(decimals,modres),nrow=nump[1,i]))
modsum<-noquote(matrix(sprintf(decimals,modsum),nrow=1))
b<-matrix(unlist(modoutz[5]))
varb<-matrix(unlist(modoutz[6]),nrow=nump[1,i])
dfmatt<-matrix(modsum[1,6],nrow(modres),1)
modsuml<-matrix(c("R","R-sq","MSE",hcflab,"df1","df2", "p"))
modresl<-t(matrix(c("coeff",hclab,"t","p","LLCI","ULCI")))
}
if ((ydich==1) & (i==(nms+nys)))
{
modoutz<-process.modelest(y,x,2,1,xp2,5,iterate,converge)
modres<-matrix(unlist(modoutz[1]),nrow=nump[1,i])
direff<-matrix(modres,nrow=ncol(x))
modsum<-matrix(unlist(modoutz[3]))
basemod<-modsum[1,1]
basemodx<-basemod
tval<-matrix(unlist(modoutz[7]))
resultm2<-matrix(99999,1,maxresm)
resultm2[1,1:nrow(modsum)]<-t(modsum)
resultm<-rbind(resultm,resultm2)
resultm2<-matrix(99999,nrow(modres),maxresm)
resultm2[1:nrow(modres),1:ncol(modres)]<-modres
resultm<-rbind(resultm,resultm2)
modrest9<-modres
modres<-noquote(matrix(sprintf(decimals,modres),nrow=nump[1,i]))
modsum<-noquote(matrix(sprintf(decimals,modsum),nrow=1))
b<-matrix(unlist(modoutz[5]))
varb<-matrix(unlist(modoutz[6]),nrow=nump[1,i])
modsuml<-matrix(c("-2LL","ModelLL", "df", "p", "McFadden", "CoxSnell", "Nagelkrk"))
modresl<-t(matrix(c("coeff","se","Z","p","LLCI","ULCI")))
#modretrn<-list(modres,modresl,modsum,modsuml,b,varb,xp2)
dfmatt<-matrix(-999,nrow(modres),1)
}
obscoeff<-cbind(obscoeff,t(b))
if (outscreen==1)
{
cat("Model Summary: \n")
colnames(modsum)<-modsuml;rownames(modsum)<-" "
print(modsum,right=T)
cat("\n")
cat("Model: \n")
rownames(modres)<-vlabsm;colnames(modres)<-modresl
print(modres,right=T)
if ((ydich==1) & (i==(nms+nys)))
{
cat("\nThese results are expressed in a log-odds metric.\n")
notecode[notes,1]<-26;notes<-notes+1
}
}
coeffmat<-rbind(coeffmat,modres)
conseqt<-matrix(outnames[i,1],nrow(modres),1)
conseq<-matrix(c(conseq,conseqt))
dfmat<-rbind(dfmat,dfmatt)
labstart<-labstart+nump[1,i]
if (stand==1)
{
predsd<-matrix(0,nrow(modres),1)
stdmod<-as.numeric(modres[,1])/ovsd[i,1]
for (jd in c(1:ncol(x)))
{
predsd[jd,1]<-sd(x[,jd])
}
if ((wherex[1,i] != -999) & ((nxvls > 1) | (xdich==1)))
{
sdmsone<-matrix(1,nxvls,1)
predsd[wherex[1,i]:wherex[2,i],1]<-sdmsone
pstog<-1
}
predsd[1,1]<-1
stdmod<-stdmod*predsd
stdmod<-matrix(stdmod[2:nrow(stdmod),1])
sdvlabs<-vlabsm[2:nrow(vlabsm),1]
if (outscreen==1){cat("\nStandardized coefficients:\n")}
resultm2<-matrix(99999,nrow(stdmod),maxresm)
resultm2[1:nrow(stdmod),1:ncol(stdmod)]<-stdmod
resultm<-rbind(resultm,resultm2)
stdmod<-noquote(matrix(sprintf(decimals,stdmod),nrow=(nump[1,i]-1)))
colnames(stdmod)<-"coeff"
rownames(stdmod)<-sdvlabs
if (outscreen==1)
{print(stdmod,right=T)}
}
if ((nms > 0) & (serial==0) & (sum(numint)==0) & ((normal==1) | (mc > 0)))
{
if (i < (nms+nys))
{
indcov[(((i-1)*nxvls)+1):(i*nxvls),(((i-1)*nxvls)+1):(i*nxvls)]<-varb[2:(1+nxvls),2:(1+nxvls)]
mcsopath[(((i-1)*nxvls)+1):(i*nxvls),1]<-matrix(modrest9[2:(1+nxvls),1])
}
if (i==(nms+nys))
{
atm<-ncol(wherem)
indcov[((nms*nxvls)+1):nrow(mcsopath),((nms*nxvls)+1):nrow(mcsopath)]<-varb[wherem[1,atm]:(wherem[1,atm]+nms-1),wherem[1,atm]:(wherem[1,atm]+nms-1)]
mcsopath[((nms*nxvls)+1):nrow(mcsopath),1]<-matrix(modrest9[wherem[1,atm]:(wherem[1,atm]+nms-1),1])
sobelok<-1
}
}
obsdirfx<-matrix(0,1,nxvls);dirzes<-matrix(0,1,nxvls)
if ((i ==(nms+nys)) & (bcmat[nrow(bcmat),1]==1))
{
direff<-matrix(direff[2:(1+nxvls),],nrow=nxvls)
obsdirfx<-t(direff[,1])
direfflb<-modresl
direffl2<-vlabsm[2:(1+nxvls),]
lmat<-matrix(0,nrow(b),1)
lmat2<-matrix(1,nxvls,1)
lmat[2:(1+nxvls),1]<-lmat2
if (ydich != 1)
{
diromni<-process.ftest3(lmat,b,varb,1,brsq2,0,y,x)
}
if (ydich==1){diromni<-process.llrtest3(lmat,y,x,b,basemod,iterate,converge)}
}
if (numint[1,i] > 0)
{
if (outscreen==1)
{
cat("\nProduct terms key:\n")
intkeym<-matrix(intkey[intstart:(intstart+numint[1,i]-1),],ncol=7)
write.table(intkeym,quote=FALSE,row.names=FALSE,col.names=FALSE,sep = " ")
}
}
if (covcoeff==1)
{
if (outscreen==1){cat("\nCovariance matrix of regression parameter estimates:\n")}
resultm2<-matrix(99999,nrow(varb),maxresm)
if (ncol(varb) <= maxresm)
{
resultm2[1:nrow(varb),1:ncol(varb)]<-varb
resultm<-rbind(resultm,resultm2)
}
if (ncol(varb) > maxresm)
{
resultmt<-matrix(99999,nrow(resultm),ncol(varb))
resultmt[1:nrow(resultm),1:ncol(resultm)]<-resultm
resultm<-resultmt
resultm2<-matrix(99999,nrow(varb),ncol(resultm))
resultm2[1:nrow(varb),1:ncol(varb)]<-varb
resultm<-rbind(resultm,resultm2)
maxresm<-ncol(resultm)
}
varbpr<-noquote(matrix(sprintf(decimals,varb),nrow=nump[1,i]))
rownames(varbpr)<-vlabsm;colnames(varbpr)<-vlabsm
if (outscreen==1)
{print(varbpr,right=T)}
}
#start X by M interaction */
if ((model != 74) & (xmtest==1) & (nms > 0))
{
r2tmp<-brsq2;btmp<-b;varbtmp<-varb
dfrestmp<-dfres
tvaltmp<-tval
xmtst<-matrix(0,nms,4)
xmtstlbc=matrix(c(hcflab,"df1","df2","p"))
if ((i==(nms+nys)) & (ydich==1))
{xmtst<-matrix(0,nms,3);xmtstlbc<-c("Chi-sq","df","p")
}
xmtstlb<-" ";xmtmat<-x;numxint<-0
if (i > 1)
{
for (xmints in (2:i))
{
x<-xmtmat
if ((bcmat[(i+1),xmints]==1) & (wzcmat[(i+1),xmints] != 1))
{
if (bcmat[(i+1),1]==0)
{
x<-cbind(xmtmat,xtmp)
if ((ydich==1) & (i==(nms+nys)))
{
LL2<-process.modelest(y,x,2,0,xp2,5,iterate,converge)
basemodx<-LL2
}
}
for (xmtlp1 in (1:nxvls))
{
mtmpmns<-sum(mtmp[,(xmints-1)])/nrow(mtmp)
x<-as.matrix(cbind(x,(xtmp[,xmtlp1]*((mtmp[,(xmints-1)])-mtmpmns))))
}
if ((i < (nms+nys)) | (ydich==0))
{
modoutz<-process.modelest(y,x,1,1,xp2,hc)
b<-matrix(unlist(modoutz[5]))
varb<-matrix(unlist(modoutz[6]),nrow=nrow(b))
lmat<-matrix(0,nrow(b),nxvls)
lmattmp<-diag(nxvls)
lmat[(nrow(lmat)-nxvls+1):nrow(lmat),]<-lmattmp
fresult2<-process.ftest3(lmat,b,varb,0,0,1,y,x)
numxint<-numxint+1
xmtst[numxint,]<-fresult2
}
#right here
if ((i==(nms+nys)) & (ydich==1))
{
LL2<-process.modelest(y,x,2,0,xp2,5,iterate,converge)
chidfxm<-(basemodx-LL2)
numxint<-numxint+1
xmtst[numxint,1]<-chidfxm
xmtst[numxint,3]<-(1-pchisq(chidfxm,df=nxvls))
}
xmtstlbt<-matrix(c(highlbx[(xmints-1),1]))
xmtstlb<-rbind(xmtstlb,xmtstlbt)
}
}
}
x<-xmtmat
if (numxint > 0)
{
xmtstlb<-matrix(xmtstlb[(2:(numxint+1)),])
xmtst<-matrix(xmtst[1:numxint,],nrow=numxint)
if (nms==1){xmtstlb<-" "}
resultm2<-matrix(99999,nrow(xmtst),maxresm)
resultm2[1:nrow(xmtst),1:ncol(xmtst)]<-xmtst
resultm<-rbind(resultm,resultm2)
if ((i < (nms+nys)) | (ydich==0))
{
xmtst<-noquote(matrix(sprintf(decimals,xmtst),ncol=4))
colnames(xmtst)<-xmtstlbc
rownames(xmtst)<-xmtstlb
if (outscreen==1)
{cat("\nTest(s) of X by M interaction:\n")
print(xmtst,right=T)}
}
if ((i==(nms+nys)) & (ydich==1))
{
xmtst<-noquote(matrix(sprintf(decimals,xmtst),ncol=3))
colnames(xmtst)<-xmtstlbc
rownames(xmtst)<-xmtstlb
if (outscreen==1)
{cat("\nLikelihood ratio test(s) of X by M interaction:\n")
print(xmtst,right=T)}
}
}
b<-btmp;varb<-varbtmp;dfres<-dfrestmp;tval<-tvaltmp;brsq2<-r2tmp
}
#end X by M interaction
#here is where we do F tests
#START F
if (criterr==0)
{
jj<-0
for (j in (start:((start+i)-1)))
{
dbint<-0
lmat<-whigh[1:nump[1,i],j]
lmat2<-wzhigh[1:nump[1,i],j]
if ((sum(lmat) > 0) & (sum(lmat2)==0))
{
if ((i < (nms+nys)) | (ydich != 1))
{
fresult2<-process.ftest3(lmat,b,varb,chr=1,brsq2,0,y,x)
lmatdb<-lmat
dbint=dbint<-1
}
if ((ydich==1) & (i==(nms+nys)))
{
fresult2<-process.llrtest3(lmat,y,x,b,basemod,iterate,converge)
lmatdb<-lmat
dbint<-dbint+1
}
highf<-rbind(highf,fresult2)
highf2<-rbind(highf2,fresult2)
if (j==start){flabel<-matrix(c(flabel,"X*W"))}
if (j > start)
{
if (nms > 1){flabel<-matrix(c(flabel,highlbw[jj,1]))}
if (nms==1)
{
if (xmint==0){flabel<-matrix(c(flabel,"M*W"))}
if (xmint==1){flabel<-matrix(c(flabel,"X*M"))}
}
}
}
lmat<-zhigh[1:nump[1,i],j]
lmat2<-wzhigh[1:nump[1,i],j]
if ((sum(lmat) > 0) & (sum(lmat2)==0))
{
if ((i < (nms+nys)) | (ydich != 1))
{
fresult2<-process.ftest3(lmat,b,varb,chr=1,brsq2,0,y,x)
dbint<-dbint+1
}
if ((ydich==1) & (i==(nms+nys)))
{
fresult2<-process.llrtest3(lmat,y,x,b,basemod,iterate,converge)
dbint<-dbint+1
}
highf<-rbind(highf,fresult2)
highf2<-rbind(highf2,fresult2)
if (j==start){flabel<-matrix(c(flabel,"X*Z"))}
if (j > start)
{
if (nms > 1){flabel<-matrix(c(flabel,highlbz[jj,1]))}
if (nms==1){flabel<-matrix(c(flabel,"M*Z"))}
}
}
if (dbint==2)
{
lmatdb<-(lmatdb+lmat)
if ((ydich==1) & (i==(nms+nys)))
{fresult2<-process.llrtest3(lmatdb,y,x,b,basemod,iterate,converge)}
if ((ydich != 1) | (i < (nms+nys)))
{
fresult2<-process.ftest3(lmatdb,b,varb,chr=1,brsq2,0,y,x)
}
dbint<-0
highf<-rbind(highf,fresult2)
if ((jj==0) & (nms > 0)){flabel<-matrix(c(flabel,"BOTH(X)"))}
if ((jj==0) & (nms==0)){flabel<-matrix(c(flabel,"BOTH"))}
if ((jj > 0) & (nms==1)){flabel<-matrix(c(flabel,"BOTH(M)"))}
if ((nms > 1) & (jj > 0)){flabel<-matrix(c(flabel,highlbbt[jj,1]))}
}
lmat2<-wzhigh[1:nump[1,i],j]
if (sum(lmat2) > 0)
{
if ((i < (nms+nys)) | (ydich != 1))
{
fresult2<-process.ftest3(lmat2,b,varb,chr=1,brsq2,0,y,x)
}
if ((ydich==1) & (i==(nms+nys)))
{fresult2<-process.llrtest3(lmat2,y,x,b,basemod,iterate,converge)}
highf<-rbind(highf,fresult2)
highf2<-rbind(highf2,fresult2)
if (j==start){flabel<-matrix(c(flabel,"X*W*Z"))}
if (j > start)
{
if (nms > 1){flabel<-matrix(c(flabel,highlbwz[jj,1]))}
if (nms==1){flabel<-matrix(c(flabel,"M*W*Z"))}
}
}
jj<-jj+1
}
start<-start+i
highfsz<-ncol(highf)
}
#END F
if (nrow(highf) > 1)
{
highf<-matrix(highf[2:nrow(highf),],ncol=highfsz)
highf2<-matrix(highf2[2:nrow(highf2),],ncol=highfsz)
flabel<-as.matrix(flabel[2:nrow(flabel),])
resultm2<-matrix(99999,nrow(highf),maxresm)
resultm2[1:nrow(highf),1:ncol(highf)]<-highf
resultm<-rbind(resultm,resultm2)
highf<-noquote(matrix(sprintf(decimals,highf),ncol=highfsz))
if (outscreen==1)
{
if ((i < (nms+nys)) | (ydich==0))
{
cat("\nTest(s) of highest order unconditional interaction(s):\n")
colnames(highf)<-matrix(c("R2-chng",hcflab,"df1","df2","p"))
rownames(highf)<-flabel
print(highf,right=T)
}
if ((ydich==1) & (i==(nms+nys)))
{
cat("\nLikelihood ratio test of highest order\n")
cat("unconditional interaction(s):\n")
colnames(highf)<-matrix(c("Chi-sq", "df","p"))
rownames(highf)<-flabel
print(highf,right=T)
}
}
intpb<-as.matrix(highf2[,ncol(highf2)])
}
intstart<-intstart+numint[1,i]
}
#END E
#Start PROBEandPLOT
if (criterr==0)
{
threeway<-0;didprint<-0;didsome<-0;sigintct<-0
#Start R
for (jmed in (1:(nms+1)))
{
hasw<-0;hasz<-0;jnok<-0;nm1vls<-0;nm2vls<-0;panelgrp<-0
focpred4<-matrix(" ")
intprint<-0;modcat<-0
#Start A
if (jmed <= i)
{
if ((jmed==1) & ((i+1)==nrow(bcmat)))
{pathscnt<-pathscnt+1} else {
paths<-cbind(paths,bcmat[(i+1),jmed])
pathsw<-cbind(pathsw,wcmat[(i+1),jmed])
pathsz<-cbind(pathsz,zcmat[(i+1),jmed])
pathswz<-cbind(pathswz,wzcmat[(i+1),jmed])
temp<-matrix(fochigh[,pathscnt]*bootloc[,i])
pathsfoc<-as.matrix(cbind(pathsfoc,pathsfoc[,1]))
if (jmed==1){pathtype<-cbind(pathtype,1)}
if ((i+1)==nrow(bcmat)){pathtype<-cbind(pathtype,3)}
if ((jmed > 1) & ((i+1) < nrow(bcmat))){pathtype<-cbind(pathtype,2)}
if ((jmed==1) & (nxvls > 1) & (bcmat[(i+1),jmed]==1))
{pathsfoc[,(pathscn2+1)]<-temp[2:(nxvls+1),1]}
if ((jmed > 1) | ((jmed==1) & (nxvls==1)))
{
temp<-matrix(apply(temp,2,max)) #column max
pathsfoc[1,(pathscn2+1)]<-temp
}
pathscnt<-pathscnt+1;pathscn2<-pathscn2+1
if (i <= nms){pathsdv<-matrix(c(pathsdv,mnames[1,i]))}
if (i > nms){pathsdv<-matrix(c(pathsdv,ynames))}
}
coeffcol<-coeffcol+1
probettt<-matrix(coeffs[1:nrow(b),coeffcol])
if ((jmed==1) & (bcmat[(i+1),jmed]==1))
{
omni<-matrix(0,nrow(probettt),nxvls)
omnitmp<-diag(nxvls)
omni[2:(1+nxvls),]<-omnitmp
}
if (sum(probettt) > 0)
{
probvarb<-matrix(999,sum(probettt),sum(probettt))
probcoef<-matrix(999,sum(probettt),1)
coefflp2<-1
for (coefflp in (1:nrow(probettt)))
{
if (probettt[coefflp,1]==1)
{
probcoef[coefflp2,1]<-b[coefflp,1]
coefflp2<-coefflp2+1
}
}
coefflp<-0;coefflp2<-0
for (iclp in (1:nrow(probettt)))
{
if (probettt[iclp,1]==1)
{
coefflp<-coefflp+1
coefflp2<-coefflp
probvarb[coefflp,coefflp]<-varb[iclp,iclp]
if (iclp < nrow(probettt))
{
for (jclp in ((iclp+1):nrow(probettt)))
{
if (probettt[jclp,1]==1)
{
coefflp2<-coefflp2+1
probvarb[coefflp,coefflp2]<-varb[iclp, jclp]
probvarb[coefflp2,coefflp]<-varb[iclp, jclp]
}
}
}
}
}
}
}
#End A
xprobval<-as.matrix(xmodvals)
if ((nxvls > 1) | (mcx > 0)){xprobval<-as.matrix(dummatx[,2:ncol(dummatx)])}
#Start B
if ((wcmat[(i+1),jmed]==1) & (zcmat[(i+1),jmed]==0))
{
numplps<-1;modvals<-wmodvals;probeval<-wmodvals;wheremv1<-wherexw
nm1vls<-nwvls;lpstsp<-t(matrix(c(1,1)));modcat<-0;jnmod<-wtmp;jnmodlab<-wnames
jnok<-1;jnmin<-wmin;jnmax<-wmax;wherejn1<-2
if (jmed==1)
{
wherejn3<-wherexw[1,i]
if (nxvls > 1){jnok<-0}
}
if (jmed > 1)
{
wherejn1<-wherem[(jmed-1),i]
wherejn3<-wheremw[((2*jmed)-3),i]
}
if (nwvls > 1)
{
probeval<-wprobval
lpstsp[1,2]<-ncol(probeval)
modcat<-1;jnok<-0
}
if (wdich==1){modcat<-1;jnok<-0}
problabs<-wnames
focpred3<-t(matrix(c(wnames,"(W)")))
if (xmint==1)
{focpred3<-t(matrix(c(wnames,"(X)")))}
hasw<-1
modgrph<-wnames;intprint<-1;sigintct<-sigintct+1;
printpbe<-intpb[sigintct,1]
}
#end B
#start C
if ((wcmat[(i+1),jmed]==0) & (zcmat[(i+1),jmed]==1))
{
numplps<-1;modvals<-zmodvals;probeval<-zmodvals;wheremv1<-wherexz
nm1vls<-nzvls;lpstsp<-t(matrix(c(1,1)));jnok<-1;jnmod<-ztmp;jnmin<-zmin;jnmax<-zmax
jnmodlab<-znames;wherejn1<-2
if (jmed==1)
{
wherejn3<-wherexz[1,i]
if (nxvls > 1){jnok<-0}
}
if (jmed > 1){wherejn1<-wherem[(jmed-1),i];wherejn3<-wheremz[((2*jmed)-3),i]}
if (nzvls > 1)
{
probeval<-zprobval;lpstsp[1,2]<-ncol(probeval);modcat<-1;jnok<-0
}
if (zdich == 1){modcat<-1;jnok<-0}
problabs<-znames
focpred3<-t(matrix(c(znames,"(Z)")))
modgrph<-znames;hasz<-1;intprint<-1;sigintct<-sigintct+1;
printpbe<-intpb[sigintct,1]
}
# end C
# start D
if ((wzcmat[(i+1),jmed]==1) | ((wcmat[(i+1),jmed]==1) & (zcmat[(i+1),jmed]==1)))
{
numplps<-2;probecnt<-1;intprint<-1
if (wzcmat[(i+1),jmed]==1)
{
sigintct<-sigintct+1;printpbe<-intpb[sigintct,1]
} else {
sigintct<-sigintct+2;printpbe<-min(intpb[(sigintct-1):sigintct,1])
}
panelgrp<-1;hasw<-1;hasz<-1
modgrph<-wnames
lpstsp<-matrix(1,2,2)
wheremv1<-wherexw;nm1vls<-nwvls;wheremv2<-wherexz;nm2vls<-nzvls;jnok<-0
if (wzcmat[(i+1),jmed]==1){jnok<-1}
if (jmed > 1){mprobval<-mmodvals}
if (jmed==1){if (nxvls > 1){jnok<-0}}
if (nwvls > 1){lpstsp[1,2]<-ncol(wprobval);modcat<-1;jnok<-0}
if (zdich==1){modcat<-1;jnok<-0}
lpstsp[2,1]<-lpstsp[1,2]+1;lpstsp[2,2]<-lpstsp[1,2]+1
if (nzvls > 1)
{
lpstsp[2,1]<-lpstsp[1,2]+1
lpstsp[2,2]<-lpstsp[1,2]+ncol(zprobval)
jnok<-0
}
if (zdich==1){jnok<-0}
omni3<-matrix(0,nrow(b),(nxvls*nwvls),0)
if (jmed > 1){omni3<-matrix(0,nrow(b),nwvls)}
focpred3<-t(matrix(c(wnames,"(W)")))
if (xmint==1)
{focpred3<-t(matrix(c(wnames,"(X)")))}
focpred4<-t(matrix(c(" Moderator:", znames, "(Z)")))
modvals<-matrix(0,(nrow(wmodvals)*nrow(zmodvals)),2)
probeval<-matrix(0,(nrow(wmodvals)*nrow(zmodvals)),(ncol(wprobval)+ncol(zprobval)))
for (probei in (1:nrow(wmodvals)))
{
for (probej in (1:nrow(zmodvals)))
{
modvals[probecnt,1]<-wmodvals[probei,1]
probeval[probecnt,1:nwvls]<-wprobval[probei,]
modvals[probecnt,2]<-zmodvals[probej,1]
probeval[probecnt,(nwvls+1):(nwvls+nzvls)]<-zprobval[probej,]
probecnt<-probecnt+1
}
}
if (wzcmat[(i+1),jmed]==1)
{
numplps<-numplps+1
probprod<-matrix(0,1,(ncol(wprobval)*ncol(zprobval)))
lpstsp2<-t(matrix(c(1,1)))
lpstsp=rbind(lpstsp,lpstsp2)
lpstsp[3,1]<-lpstsp[2,2]+1
lpstsp[3,2]<-lpstsp[2,2]+ncol(probprod)
jnmod<-ztmp;jnmin<-zmin;jnmax<-zmax;jnmodlab<-znames
if (jmed == 1){wherejn1<-wherexw[1,i];wherejn3<-wherexwz[1,i]}
if (jmed > 1)
{
wherejn1<-wheremw[((2*jmed)-3),i]
wherejn3<-wheremwz[((2*jmed)-3),i]
}
for (probei in (1:nrow(wmodvals)))
{
for (probej in (1:nrow(zmodvals)))
{
probtemp<-1
for (probek in (1:ncol(wprobval)))
{
#probtemp<-cbind(probtemp,(wprobval[probei,probek]*zprobval[probej,]))
probtemp<-cbind(probtemp,matrix((wprobval[probei,probek]*zprobval[probej,]),ncol=ncol(zprobval)))
}
probprod<-rbind(probprod,probtemp[1,2:ncol(probtemp)])
}
}
probprod<-probprod[2:nrow(probprod),]
probeval<-cbind(probeval,probprod)
}
problabs<-cbind(wnames,znames)
}
# end D
# start E
if (intprint==1)
{
focpred<-"Focal predictor:"
if (jmed==1)
{focpred<-cbind(focpred,xnames,"(X)");focplotv<-as.matrix(xmodvals)}
if (jmed >1)
{
if (nms > 1){focpred<-cbind(focpred,mnames[1,(jmed-1)], medlb2[(jmed-1),1])}
if (nms==1){focpred<-cbind(focpred,mnames[1,(jmed-1)], "(M)")}
focplotv<-as.matrix(mmodvals[,(jmed-1)],nrow=nrow(mmodvals))
}
focpred2<-cbind(" Moderator:",focpred3)
focpred<-rbind(focpred,focpred2)
if (ncol(focpred4) > 1){focpred<-rbind(focpred,focpred4);focpred4<-matrix(c(" "))}
if (outscreen==1)
{
if (((plot==1) | (plot==2)) | (printpbe <= intprobe))
{cat("----------\n");write.table(focpred,quote=FALSE,row.names=FALSE,col.names=FALSE)}
}
foctmp<-matrix(1,nrow(modvals),1)
probexpl<-1
probeva2<-cbind(foctmp,probeval)
if ((jmed==1) & (nxs > 0) & (mcx > 0)){probexpl<-nxvls}
foctmp<-matrix(1,nrow(modvals),1)
modvals3<-matrix(0,1,(6+ncol(problabs)))
probrown<-matrix(0,nrow(probeval),1)
jtmp<-1
for (probei in (1:nrow(probeval))){probrown[probei,1]<-jtmp;jtmp<-jtmp+nxvls}
probrow<-999;modvarl<-problabs
# start F */
if ((plot==1) | (plot==2) | (nxvls > 1))
{
plotvals<-matrix(999,(nrow(modvals)*nrow(focplotv)),(ncol(modvals)+1))
for (ploti in (1:nrow(modvals)))
{
for (plotj in (1:nrow(focplotv)))
{
plotvals[(((ploti-1)*nrow(focplotv))+plotj),2:ncol(plotvals)]<-modvals[ploti,]
plotvals[(((ploti-1)*nrow(focplotv))+plotj),1]<-focplotv[plotj,1]
}
}
focpredn<-3
if (jmed==1)
{
if (nxvls > 1){focpredn<-(nxvls+1)}
if ((nxvls==1) & (xdich==1)){focpredn<-2}
}
meanmat<-diag(c(means))
onesmat<-matrix(1,nrow(meanmat),(nrow(probeval)*focpredn))
probeplt<-t(diag(means)%*%onesmat)
# start G
if (jmed==1)
{
if ((wcmat[(i+1),1]==1) | (zcmat[(i+1),1]==1))
{
plotcnt<-1;iloops<-nwpval*nzpval;plotmx<-nxpval*nzpval
if ((wcmat[(i+1),1]==1) & (zcmat[(i+1),1]==0))
{iloops<-nwpval;plotmx<-nxpval}
if ((wcmat[(i+1),1]==0) & (zcmat[(i+1),1]==1))
{iloops<-nzpval;plotmx<-nxpval}
xestvals<-matrix(-999,(nxpval*iloops),ncol(xprobval))
if (wcmat[(i+1),1]==1){westvals<-matrix(-999,nrow(xestvals),ncol(wprobval))}
if (zcmat[(i+1),1]==1){zestvals<-matrix(-999,nrow(xestvals),ncol(zprobval))}
for (ploti in (1:iloops))
{
for (plotj in (1:nxpval))
{xestvals[plotcnt,]<-xprobval[plotj,];plotcnt<-plotcnt+1}
}
plotcnt<-1;plotcnt1<-1;plotcnt2<-1;plotcntz<-1
for (ploti in (1:(iloops*nxpval)))
{
if (wcmat[(i+1),1]==1){westvals[ploti,]=wprobval[plotcnt1,]}
if ((wcmat[(i+1),1]==0) & (zcmat[(i+1),1]==1))
{zestvals[ploti,]<-zprobval[plotcnt1,]}
if ((wcmat[(i+1),1]==1) & (zcmat[(i+1),1]==1))
{zestvals[ploti,]<-zprobval[plotcnt2,];plotcntz=plotcntz+1}
plotcnt<-plotcnt+1
if (plotcnt > plotmx){plotcnt<-1;plotcnt1<-plotcnt1+1}
if (plotcntz > nxpval)
{
plotcnt2<-plotcnt2+1;plotcntz<-1
if (plotcnt2 > nzpval){plotcnt2<-1}
}
}
probeplt[,2:(1+(ncol(xestvals)))]<-xestvals
if (wcmat[(i+1),1]==1)
{probeplt[,wherew[1,i]:wherew[2,i]]<-westvals}
if (zcmat[(i+1),1]==1)
{probeplt[,wherez[1,i]:wherez[2,i]]<-zestvals}
}
}
# end G
# start H
if (jmed > 1)
{
if ((wcmat[(i+1),jmed]==1) | (zcmat[(i+1),jmed]==1))
{
plotcnt<-1;iloops<-(nwpval*nzpval);plotmx<-(3*nzpval)
if ((wcmat[(i+1),jmed]==1) & (zcmat[(i+1),jmed]==0))
{iloops<-nwpval;plotmx<-3}
if ((wcmat[(i+1),jmed]==0) & (zcmat[(i+1),jmed]==1))
{iloops<-nzpval;plotmx<-3}
mestvals<-matrix(-999,(3*iloops),1)
if (wcmat[(i+1),jmed]==1)
{westvals<-matrix(-999,nrow(mestvals),ncol(wprobval))}
if (zcmat[(i+1),jmed]==1)
{zestvals<-matrix(-999,nrow(mestvals),ncol(zprobval))}
for (ploti in (1:iloops))
{
for (plotj in (1:3))
{
mestvals[plotcnt,]<-mprobval[plotj,(jmed-1)]
plotcnt<-plotcnt+1
}
}
plotcnt<-1;plotcnt1<-1;plotcnt2<-1;plotcntz<-1
for (ploti in (1:(iloops*3)))
{
if (wcmat[(i+1),jmed]==1)
{westvals[ploti,]<-wprobval[plotcnt1,]}
if ((wcmat[(i+1),jmed]==0) & (zcmat[(i+1),jmed]==1))
{zestvals[ploti,]<-zprobval[plotcnt1,]}
if ((wcmat[(i+1),jmed]==1) & (zcmat[(i+1),jmed]==1))
{zestvals[ploti,]<-zprobval[plotcnt2,];plotcntz<-plotcntz+1}
plotcnt<-plotcnt+1
if (plotcnt > plotmx){plotcnt<-1;plotcnt1<-plotcnt1+1}
if (plotcntz > 3)
{
plotcnt2<-plotcnt2+1;plotcntz<-1
if (plotcnt2 > nzpval){plotcnt2<-1}
}
}
probeplt[,wherem[(jmed-1),i]]<-mestvals
if (wcmat[(i+1),jmed]==1)
{
if (model != 74)
{probeplt[,(wherew[1,i]):(wherew[2,i])]<-westvals}
if (model==74)
{probeplt[,(wherex[1,i]):(wherex[2,i])]<-westvals}
}
if (zcmat[(i+1),jmed]==1)
{probeplt[,(wherez[1,i]):(wherez[2,i])]<-zestvals}
}
}
# end H
# Here I am doing the multiplications to produce data for the plot
prodloop <-1
if (jmed==1){prodloop<-ncol(xestvals)}
if ((wcmat[(i+1),jmed])==1)
{
plotcnt<-0
for (ploti in (1:prodloop))
{
for (plotj in (1:ncol(westvals)))
{
if (jmed==1)
{probeplt[,(wherexw[1,i]+plotcnt)]<-(xestvals[,ploti]*westvals[,plotj])}
if (jmed > 1)
{probeplt[,(wheremw[((jmed*2)-3) ,i]+plotcnt)]<-(mestvals[,ploti]*westvals[,plotj])}
plotcnt<-plotcnt+1
}
}
}
if ((zcmat[(i+1),jmed])==1)
{
plotcnt<-0
for (ploti in (1:prodloop))
{
for (plotj in (1:ncol(zestvals)))
{
if (jmed==1)
{probeplt[,(wherexz[1,i]+plotcnt)]<-(xestvals[,ploti]*zestvals[,plotj])}
if (jmed > 1)
{probeplt[,(wheremz[((jmed*2)-3),i]+plotcnt)]<-(mestvals[,ploti]*zestvals[,plotj])}
plotcnt<-plotcnt+1
}
}
}
if ((wzcmat[(i+1),jmed])==1)
{
plotcnt<-0;threeway<-1
for (ploti in (1:ncol(westvals)))
{
for (plotj in (1:ncol(zestvals)))
{
probeplt[,(wherewz[1,i]+plotcnt)]<-(westvals[,ploti]*zestvals[,plotj])
plotcnt<-plotcnt+1
}
}
plotcnt<-0
for (plotk in (1:prodloop))
{
for (ploti in (1:ncol(westvals)))
{
for (plotj in (1:ncol(zestvals)))
{
if (jmed==1)
{probeplt[,(wherexwz[1,i]+plotcnt)]<-(xestvals[,plotk]*westvals[,ploti]*zestvals[,plotj])}
if (jmed > 1)
{probeplt[,(wheremwz[((jmed*2)-3),i]+plotcnt)]<-(mestvals[,plotk]*westvals[,ploti]*zestvals[,plotj])}
plotcnt<-plotcnt+1
}
}
}
}
# here is where we add holding constant products as needed
# start I
for (newplp in (1:i))
{
if (newplp != jmed)
{
if (wcmat[(i+1),newplp]==1)
{
prodloop<-1
if (newplp==1){prodloop<-nxvls}
plotcnt<-0
for (ploti in (1:prodloop))
{
for (plotj in (1:nwvls))
{
if (newplp==1)
{probeplt[,(wherexw[1,i]+plotcnt)]<-probeplt[,(1+ploti)]*probeplt[,(wherew[1,i]+plotj-1)]}
if (newplp > 1)
{
if (model != 74)
{probeplt[,(wheremw[((newplp*2)-3) ,i]+plotcnt)]<-probeplt[,wherem[(newplp-1),i]]*probeplt[,(wherew[1,i]+plotj-1)]}
if (model==74)
{probeplt[,(wheremw[((newplp*2)-3) ,i]+plotcnt)]<-probeplt[,wherem[(newplp-1),i]]*probeplt[,(wherex[1,i]+plotj-1)]}
}
plotcnt<-plotcnt+1
}
}
}
if (zcmat[(i+1),newplp]==1)
{
prodloop<-1
if (newplp==1){prodloop<-nxvls}
plotcnt<-0
for (ploti in (1:prodloop))
{
for (plotj in (1:nzvls))
{
if (newplp==1)
{probeplt[,(wherexz[1,i]+plotcnt)]<-probeplt[,(1+ploti)]*probeplt[,(wherez[1,i]+plotj-1)]}
if (newplp > 1)
{probeplt[,(wheremz[((newplp*2)-3),i]+plotcnt)]<-probeplt[,wherem[(newplp-1),i]]*probeplt[,(wherez[1,i]+plotj-1)]}
plotcnt<-plotcnt+1
}
}
}
if (wzcmat[(i+1),newplp]==1)
{
plotcnt<-0
if (threeway==0)
{
for (ploti in (1:nwvls))
{
for (plotj in (1:nzvls))
{
probeplt[,(wherewz[1,i]+plotcnt)]<-probeplt[,(wherew[1,i]+ploti-1)]*probeplt[,(wherez[1,i]+plotj-1)]
plotcnt<-plotcnt+1
}
}
}
prodloop<-1
if (newplp==1){prodloop<-nxvls}
plotcnt<-0
for (plotk in (1:prodloop))
{
for (ploti in (1:nwvls))
{
for (plotj in (1:nzvls))
{
if (newplp==1)
{probeplt[,(wherexwz[1,i]+plotcnt)]<-probeplt[,(1+plotk)]*probeplt[,(wherew[1,i]+ploti-1)]*probeplt[,(wherez[1,i]+plotj-1)]}
if (newplp > 1)
{probeplt[,(wheremwz[((newplp*2)-3),i]+plotcnt)]<-probeplt[,wherem[(newplp-1),i]]*probeplt[,(wherew[1,i]+ploti-1)]*probeplt[,(wherez[1,i]+plotj-1)]}
plotcnt<-plotcnt+1
}
}
}
}
}
}
#END I
predvals<-probeplt%*%b
if ((i==(nms+nys)) & (ydich==1))
{
predvalt<-as.numeric(predvals < 709.7)
prevalt7<-(1-predvalt)*(709.7)
predvals<-(predvals*predvalt)+prevalt7
expyhat<-exp(predvals)/(1+exp(predvals))
}
sepred<-matrix(999,nrow(plotvals),3)
for (sei in (1:nrow(plotvals)))
{
ask<-as.matrix(probeplt[sei,],ncol=ncol(probeplt))
sepred[sei,1]<-sqrt(t(ask)%*%varb%*%ask)
if ((i < (nms+nys)) | (ydich==0))
{
sepred[sei,2]<-predvals[sei,1]-tval*sepred[sei,1]
sepred[sei,3]<-predvals[sei,1]+tval*sepred[sei,1]
}
if ((i==(nms+nys)) & (ydich==1))
{
sepred[sei,2]<-predvals[sei,1]-xp2*sepred[sei,1]
sepred[sei,3]<-predvals[sei,1]+xp2*sepred[sei,1]
}
}
prevloc<-ncol(plotvals)+1
probeplt<-cbind(plotvals,predvals)
if (plot==2){probeplt<-cbind(probeplt,sepred)}
if ((i==(nms+nys)) & (ydich==1))
{probeplt<-cbind(probeplt,expyhat)}
didsome<-0
}
# END F
# here is the loop that is printing the conditional effects
# this does conditional two way interactions
# START J
if ((wzcmat[(i+1),jmed]==1) & (printpbe <= intprobe))
{
if (jmed==1)
{omnilp2<-nxvls*nwvls;omnitmp<-diag(omnilp2);omni3[wherexw[1,i]:wherexw[2,i],]<-omnitmp}
if (jmed>1)
{omnilp2<-nwvls;omnitmp<-diag(omnilp2);omni3[wheremw[((jmed*2)-3),i]:wheremw[((jmed*2)-2),i],]<-omnitmp}
omnif<-matrix(0,1,4)
if ((i==(nms+nys)) & (ydich==1))
{omnif<-matrix(0,1,3)}
condeff3<-0
for (omnilp1 in (1:nrow(zprobval)))
{
for (omnilp in (1:omnilp2))
{
if (jmed==1)
{
omni3[(wherexwz[1,i]+((omnilp-1)*nzvls)):(wherexwz[1,i]+((omnilp-1)*nzvls)+(nzvls-1)),omnilp]<-t(zprobval[omnilp1,])
}
if (jmed > 1)
{
omni3[(wheremwz[((jmed*2)-3),i]+((omnilp-1)*nzvls)):(wheremwz[((jmed*2)-3),i]+((omnilp-1)*nzvls)+(nzvls-1)),omnilp]<-t(zprobval[omnilp1,])
}
}
condeff<-t(omni3)%*%b
condeff3<-rbind(condeff3,condeff)
fresult2<-process.ftest3(omni3,b,varb,chr=0,brsq2,1,y,x)
if ((i==(nms+nys)) & (ydich==1))
{
fratio<-fresult2[1,1]*ncol(omni3)
pfr<-(1-pchisq(fratio,df=ncol(omni3)))
fresult2<-cbind(fratio,ncol(omni3),pfr)
}
omnif<-rbind(omnif,fresult2)
}
omnif<-matrix(omnif[2:nrow(omnif),],ncol=ncol(omnif))
clabtmp<-znames
condeff3<-matrix(condeff3[2:nrow(condeff3),],ncol=ncol(condeff3))
if ((nxvls*nwvls)==1)
{
omnif<-cbind(condeff3,omnif)
clabtmp<-cbind(clabtmp,"effect")
}
omnif<-cbind(zmodvals,omnif)
if ((i < nms+nys) | (ydich==0))
{clabtmp<-c(clabtmp,hcflab,"df1","df2","p")}
if ((i==(nms+nys)) & (ydich==1))
{clabtmp<-c(clabtmp,"Chi-sq","df","p")}
resultm2<-matrix(99999,nrow(omnif),maxresm)
resultm2[1:nrow(omnif),1:ncol(omnif)]<-omnif
resultm<-rbind(resultm,resultm2)
omnif2<-noquote(matrix(sprintf(decimals,omnif),nrow=nrow(omnif)))
colnames(omnif2)<-clabtmp
rownames(omnif2)<-t(matrix(replicate(nrow(omnif)," ")))
if (outscreen==1)
{
if (jmed==1)
{cat("\nTest of conditional X*W interaction at value(s) of Z:\n")
print(omnif2,right=T)}
if (jmed > 1)
{cat("\nTest of conditional M*W interaction at value(s) of Z:\n")
print(omnif2,right=T)}
}
}
# END J
# start O
for (probei in (1:probexpl))
{
if (probexpl > 1)
{
foctmp<-matrix(0,nrow(modvals),probexpl)
foctmp[,probei]<-foctmp[,probei]+1
probtemp<-matrix(0,nrow(modvals),1)
for (probem in (1:numplps))
{for (probek in (1:nxvls))
{for (probej in (lpstsp[probem,1]:lpstsp[probem,2]))
{probtemp<-cbind(probtemp,foctmp[,probek]*probeval[,probej])}
}
}
probeva2<-probtemp[,2:ncol(probtemp)]
probeva2<-cbind(foctmp,probeva2)
}
probres<-probeva2%*%probcoef
probrese<-as.matrix(sqrt(diag(probeva2%*%probvarb%*%t(probeva2))))
tratio<-probres/probrese
if ((ydich==1) & (i==(nms+nys)))
{
p<-2*(1-pnorm(abs(tratio)))
} else {
p<-2*pt(-abs(tratio),df=dfres)
}
modvals2<-cbind(modvals,probres,probrese,tratio, p)
if ((i < nms+nys) | (ydich==0))
{
modvals2<-cbind(modvals2,(probres-as.numeric(tval)*probrese),(probres+as.numeric(tval)*probrese))
problabs<-cbind(problabs,"effect",hclab,"t", "p", "LLCI", "ULCI")
}
if ((ydich==1) & (i==(nms+nys)))
{
modvals2<-cbind(modvals2,(probres-xp2*probrese),(probres+xp2*probrese))
problabs<-cbind(problabs,"effect","se","Z", "p", "LLCI", "ULCI")
}
# start L
if ((probexpl > 1) & (printpbe <= intprobe))
{
if (hasz==1){printz<-1}
if (hasw==1){printw<-1}
probrlab<-matrix(xcatlab[probei,1],nrow(modvals),1)
modvals3<-rbind(modvals3,modvals2)
probrow<-rbind(probrow,probrown)
probrown<-probrown+1
if (probei==probexpl)
{
xproblab<-xcatlab[1:nxvls,1]
probrow<-matrix(probrow[2:nrow(probrow),1])
modvals3<-modvals3[2:nrow(modvals3),]
#modvals3<-modvals3[order(modvals3[,1]),]
modvals3<-modvals3[order(probrow[,1]),]
start2<-1
problabs<-problabs[1,(1+(ncol(modvarl))):ncol(problabs)]
pstart<-1
# start K
for (probek in (1:nrow(probeval)))
{
endstart<-start2+(nxvls-1)
temp<-modvals3[start2:endstart,(1+ncol(modvarl)):ncol(modvals3)]
temp2<-t(modvals3[start2:start2,1:ncol(modvarl)])
trnames<-t(modvarl)
if (outscreen==1)
{
if (probek > 1){cat("----------\n")}
if (probek==1)
{
cat("\nConditional effects of the focal predictor at values of the moderator(s):\n")
if ((jmed==1) & (i ==(nms+nys)) & (nms > 0))
{
if (nxvls==1)
{cat("\n(These are also the conditional direct effects of X on Y.)\n")}
if (nxvls != 1)
{cat("\n(These are also the relative conditional direct effects of X on Y.)\n")}
}
cat("\n")
}
cat("Moderator value(s):\n")
}
resultm2<-matrix(99999,nrow(temp2),maxresm)
resultm2[1:nrow(temp2),1:ncol(temp2)]<-temp2
resultm<-rbind(resultm,resultm2)
temp2<-noquote(matrix(sprintf(decimals,temp2),nrow=nrow(temp2)))
temp3<-matrix(temp2[1,1:ncol(temp2)])
rownames(temp3)<-trnames
colnames(temp3)<-" "
if (outscreen==1)
{print(temp3,right=TRUE,quote=FALSE)
cat("\n")}
#for (mdpntr in (1:ncol(temp2)))
#{
#write.table(temp2[1,mdpntr],quote=FALSE,row.names=trnames[mdpntr,1],col.names=FALSE)
#}
resultm2<-matrix(99999,nrow(temp),maxresm)
resultm2[1:nrow(temp),1:ncol(temp)]<-temp
resultm<-rbind(resultm,resultm2)
temp<-noquote(matrix(sprintf(decimals,temp),nrow=nrow(temp)))
colnames(temp)<-problabs[1:ncol(temp)]
rownames(temp)<-xproblab
if (outscreen==1)
{print(temp,right=T)}
start2<-start2+nxvls
didsome<-1
if (jmed==1)
{
mod1val<-probeval[probek,1:nm1vls]
for (omnilp in (1:nxvls))
{
omni[(wheremv1[1,i]+((omnilp-1)*nm1vls)):(wheremv1[1,i]+((omnilp-1)*nm1vls)+(nm1vls-1)),omnilp]<-t(mod1val)
if (nm1vls < ncol(probeval))
{
mod2val<-probeval[probek,(nm1vls+1):(nm1vls+nm2vls)]
omni[(wheremv2[1,i]+((omnilp-1)*nm2vls)):(wheremv2[1,i]+((omnilp-1)*nm2vls)+(nm2vls-1)),omnilp]<-t(mod2val)
if ((nm1vls+nm2vls) < ncol(probeval))
{
intlen<-(nm1vls*nm2vls)
modintvl<-probeval[probek,(nm1vls+nm2vls+1):ncol(probeval)]
omni[(wherexwz[1,i]+((omnilp-1)*intlen)):(wherexwz[1,i]+((omnilp-1)*intlen)+(intlen-1)),omnilp]<-t(modintvl)
}
}
}
fresult2<-process.ftest3(omni,b,varb,0,brsq2,1,y,x)
if ((i == (nms+nys)) & (ydich==1))
{
fratio<-fresult2[1,1]*nxvls
pfr<-(1-pchisq(fratio,df=nxvls))
fresult2<-cbind(fratio,nxvls,pfr)
}
resultm2<-matrix(99999,nrow(fresult2),maxresm)
resultm2[1:nrow(fresult2),1:ncol(fresult2)]<-fresult2
resultm<-rbind(resultm,resultm2)
fresult2<-noquote(matrix(sprintf(decimals,fresult2),nrow=nrow(fresult2)))
if (outscreen==1)
{
if (i < (nms + nys) | (ydich == 0))
{
cat("\nTest of equality of conditional means\n")
colnames(fresult2)<-c(hcflab,"df1","df2","p")
rownames(fresult2)<-" "
print(fresult2,right=T)
}
if ((i==(nms + nys)) & (ydich==1))
{
cat("\nTest of equality of conditional logits or probabilities\n")
rownames(fresult2)<-" "
colnames(fresult2)<-c("Chi-sq","df","p")
print(fresult2,right=T)
}
}
probetmp<-probeplt[pstart:(pstart+nxvls),1]
probetmp<-cbind(probetmp,probeplt[pstart:(pstart+nxvls),prevloc:ncol(probeplt)])
pstart<-pstart+(nxvls+1)
resultm2<-matrix(99999,nrow(probetmp),maxresm)
resultm2[1:nrow(probetmp),1:ncol(probetmp)]<-probetmp
resultm<-rbind(resultm,resultm2)
probetmp<-noquote(matrix(sprintf(decimals,probetmp),nrow=nrow(probetmp)))
if (outscreen==1)
{
if (i < ((nms + nys)) | (ydich==0))
{
clabtmp<-cbind(xnames, outnames[i,1], hclab, "LLCI", "ULCI")
cat("\nEstimated conditional means being compared:\n")
colnames(probetmp)<-clabtmp[1:ncol(probetmp)]
rownames(probetmp)<-t(matrix(replicate(nrow(probetmp)," ")))
print(probetmp,right=T)
}
if ((i==(nms+nys)) & (ydich==1))
{
cat("\nEstimated conditional logits and probabilities:\n")
clabtmp<-c(xnames, outnames[i,1], "prob")
probetm2<-matrix(probetmp[,1:2],ncol=2)
probetm2<-cbind(probetm2,probetmp[,ncol(probetmp)])
probetm2<-noquote(probetm2)
colnames(probetm2)<-clabtmp[1:ncol(probetm2)]
rownames(probetm2)<-t(matrix(replicate(nrow(probetm2)," ")))
print(probetm2,right=T)
}
}
}
}
# end K
}
}
# end L
# start N
if ((probexpl==1) & (printpbe <= intprobe))
{
resultm2<-matrix(99999,nrow(modvals2),maxresm)
resultm2[1:nrow(modvals2),1:ncol(modvals2)]<-modvals2
resultm<-rbind(resultm,resultm2)
modva2<-noquote(matrix(sprintf(decimals,modvals2),nrow=nrow(modvals2)))
colnames(modva2)<-problabs[1:ncol(modva2)]
rownames(modva2)<-t(matrix(replicate(nrow(modva2)," ")))
if (outscreen==1)
{cat("\nConditional effects of the focal predictor at values of the moderator(s):\n")
print(modva2,right=T)}
didsome<-1
if (hasz==1){printz<-1}
if (hasw==1){printw<-1}
# start M (JN method)
if ((jn==1) & (jnok==1))
{
if (criterr==0)
{
dfres<-(n-nrow(b));
roots<-as.matrix(99999)
jncrit<-(dfres* (exp((dfres-(5/6))*((xp2/(dfres-(2/3)+(.11/dfres)))*(xp2/(dfres-(2/3)+(.11/dfres)))))-1))
if ((i ==(nms+nys)) & (ydich==1)){jncrit<-xp2*xp2}
jnb1<-b[wherejn1,1]
jnb3<-b[wherejn3,1]
jnsb1<-varb[wherejn1,wherejn1]
jnsb3<-varb[wherejn3,wherejn3]
jnsb1b3<-varb[wherejn1,wherejn3]
ajn<-(jncrit*jnsb3)-(jnb3*jnb3)
bjn<-2*((jncrit*jnsb1b3)-(jnb1*jnb3))
cjn<-((jncrit*jnsb1)-(jnb1*jnb1))
radarg<-(bjn*bjn)-(4*ajn*cjn)
den<-2*ajn
nrts<-0
if ((radarg >= 0) & (den != 0))
{
x21<-(-bjn+sqrt(radarg))/den
x22<-(-bjn-sqrt(radarg))/den
if ((x21 >= jnmin) & (x21 <= jnmax))
{nrts<-1;roots<-rbind(roots,x21)}
if ((x22 >= jnmin) & (x22 <= jnmax))
{nrts<-nrts+1;roots<-rbind(roots,x22)}
roots<-cbind(roots,matrix(0,nrow(roots),2))
}
if (nrts > 0)
{
roots<-matrix(roots[2:nrow(roots),1:3],ncol=3)
roots[1,2]<-sum((as.numeric(jnmod < roots[1,1]))/n)*100
roots[1,3]<-sum((as.numeric(jnmod > roots[1,1]))/n)*100
if (nrow(roots)==2)
{
roots[2,2]<-sum((as.numeric(jnmod < roots[2,1]))/n)*100
roots[2,3]<-sum((as.numeric(jnmod > roots[2,1]))/n)*100
}
roots2<-noquote(matrix(sprintf(decimals,roots),nrow=nrow(roots)))
colnames(roots2)<-c("Value", "% below", "% above")
rownames(roots2)<-t(matrix(replicate(nrow(roots)," ")))
if (nrts==1){tmprts=matrix(99999,1,3);roots<-rbind(roots,tmprts)}
if (outscreen==1)
{cat("\nModerator value(s) defining Johnson-Neyman significance region(s):\n")
print(roots2,right=T)}
}
if (nrts==0)
{
roots<-as.matrix(c(99999,99999))
if (outscreen==1)
{cat("\nThere are no statistical significance transition points within the observed\n")
cat("range of the moderator found using the Johnson-Neyman method.\n")}
}
resultm2<-matrix(99999,nrow(roots),maxresm)
resultm2[1:nrow(roots),1:ncol(roots)]<-roots
resultm<-rbind(resultm,resultm2)
jnvals<-matrix(0,23,7)
for (jni in (0:(21-nrts)))
{jnvals[(jni+1),1]<-jnmin+(jni*((jnmax-jnmin)/(21-nrts)))}
if (nrts > 0)
{
for (jni in (1:nrts))
{
for (jnj in (2:nrow(jnvals)))
{
if ((roots[jni,1] > jnvals[(jnj-1),1]) & (roots[jni,1] < jnvals[jnj,1]))
{
jnvals[(jnj+1):(21+jni),1]<-jnvals[jnj:(20+jni),1]
jnvals[jnj,1]<-roots[jni,1]
}
}
}
}
jnvals<-jnvals[1:22,]
for (jni in (1:nrow(jnvals)))
{
jnvals[jni,2]<-jnb1+jnb3*jnvals[jni,1]
jnvals[jni,3]<-sqrt(jnsb1+2*jnvals[jni,1]*jnsb1b3+(jnvals[jni,1]*jnvals[jni,1])*jnsb3)
jnvals[jni,4]<-jnvals[jni,2]/jnvals[jni,3]
jnvals[jni,5]<-2*pt(-abs(jnvals[jni,4]), df=dfres)
jnvals[jni,6]<-jnvals[jni,2]-sqrt(jncrit)*jnvals[jni,3]
jnvals[jni,7]<-jnvals[jni,2]+sqrt(jncrit)*jnvals[jni,3]
if ((i==(nms + nys)) & (ydich==1))
{
jnvals[jni,5]<-2*(1-pnorm(abs(jnvals[jni,4])))
jnvals[jni,6]<-jnvals[jni,2]-xp2*jnvals[jni,3]
jnvals[jni,7]<-jnvals[jni,2]+xp2*jnvals[jni,3]
}
}
resultm2<-matrix(99999,nrow(jnvals),maxresm)
resultm2[1:nrow(jnvals),1:ncol(jnvals)]<-jnvals
resultm<-rbind(resultm,resultm2)
jnvals2<-noquote(matrix(sprintf(decimals,jnvals),nrow=nrow(jnvals)))
rownames(jnvals2)<-t(matrix(replicate(nrow(jnvals)," ")))
if ((i < nms+nys) | (ydich==0))
{colnames(jnvals2)<-c(jnmodlab,"effect", hclab, "t", "p", "LLCI", "ULCI")}
if ((i==(nms+nys)) & (ydich==1))
{colnames(jnvals2)<-c(jnmodlab,"effect","se","Z", "p", "LLCI", "ULCI")}
if (outscreen==1)
{
if (((wcmat[(i+1),jmed]==1) | (zcmat[(i+1),jmed]==1)) & (wzcmat[(i+1),jmed]==0))
{cat("\nConditional effect of focal predictor at values of the moderator:\n");print(jnvals2,right=T)}
if ((jmed==1) & (wzcmat[(i+1),jmed]==1))
{cat("\nConditional X*W interaction at values of the moderator Z:\n");print(jnvals2,right=T)}
if ((jmed > 1) & (wzcmat[(i+1),jmed]==1))
{cat("\nConditional M*W interaction at values of the moderator Z:\n");print(jnvals2,right=T)}
}
}
}
# END M (JN method)
}
if ((i==(nms+nys)) & (jmed==1) & (bcmat[nrow(bcmat),1]==1))
{
if (probei==1)
{direfflb<-problabs;direff<-modvals2}
if (probei>1)
{direff<-rbind(direff,modvals2)}
}
intprint<-0
# This does the contrast for conditional effects */
if ((jmed==1) & (i==1) & (nms==0) & (modcok==1))
{
contvec2=matrix(1,2,1)
contvec2<-cbind(contvec2,wcontval,zcontval)
if (wzcmat[(i+1),jmed]==1)
{
for (conti in (1:ncol(wcontval)))
{
for (contj in (1:ncol(zcontval)))
{contvec2<-cbind(contvec2,wcontval[,conti]*zcontval[,contj])}
}
}
conteff<-contvec2%*%probcoef
contdiff<-matrix(contvec2[1,]-contvec2[2,])
contse<-sqrt(t(contdiff)%*%probvarb%*%contdiff)
conteffd<-conteff[1,1]-conteff[2,1]
contvec=cbind(contvec,conteff)
contvecm<-contvec
resultm2<-matrix(99999,nrow(contvecm),maxresm)
resultm2[1:nrow(contvecm),1:ncol(contvecm)]<-contvecm
resultm<-rbind(resultm,resultm2)
contvecm<-noquote(matrix(sprintf(decimals,contvecm),nrow=nrow(contvecm)))
rownames(contvecm)<-c("Effect1:","Effect2:")
colnames(contvecm)<-problabs[1:3]
if (outscreen==1)
{cat("\nContrast between conditional effects of X:\n")
print(contvecm,right=T)}
if (ydich==0)
{
p<-2*pt(-abs(conteffd/contse),df=dfres)
contvec<-cbind(conteffd,contse,conteffd/contse, p)
contvec<-cbind(contvec,(conteffd-(tval*contse)))
contvec<-cbind(contvec,(conteffd+(tval*contse)))
contlabs<-c("Contrast", hclab, "t", "p", "LLCI", "ULCI")
}
if (ydich==1)
{
p<-2*(1-pnorm(abs(conteffd/contse)))
contvec<-cbind(conteffd,contse,conteffd/contse, p)
contvec<-cbind(contvec,(conteffd-(xp2*contse)))
contvec<-cbind(contvec,(conteffd+(xp2*contse)))
contlabs<-c("Contrast", "se", "Z", "p", "LLCI", "ULCI")
}
resultm2<-matrix(99999,nrow(contvec),maxresm)
resultm2[1:nrow(contvec),1:ncol(contvec)]<-contvec
resultm<-rbind(resultm,resultm2)
contvec<-noquote(matrix(sprintf(decimals,contvec),nrow=nrow(contvec)))
colnames(contvec)<-contlabs
rownames(contvec)<-" "
if (outscreen==1)
{cat("\nTest of Effect1 minus Effect2\n")
print(contvec,right=T)}
}
}
# end O
if ((plot==1) | (plot==2))
{
datalabs<-cbind(t(focpred[,2]),outnames[i,1])
if (plot==2)
{datalabs<-c(datalabs,"se", "LLCI", "ULCI")}
if ((i==(nms+nys)) & (ydich==1))
{datalabs<-c(datalabs,"prob")}
resultm2<-matrix(99999,nrow(probeplt),maxresm)
resultm2[1:nrow(probeplt),1:ncol(probeplt)]<-probeplt
resultm<-rbind(resultm,resultm2)
probepnt<-noquote(matrix(sprintf(decimals,probeplt),nrow=nrow(probeplt)))
colnames(probepnt)<-datalabs
rownames(probepnt)<-t(matrix(replicate(nrow(probepnt)," ")))
if (outscreen==1)
{cat("\nData for visualizing the conditional effect of the focal predictor:\n")
print(probepnt,right=T)}
}
}
#End E
}
#End R
}
#End PROBEandPLOT
if ((model==74) & (i <= nms))
{
onetemp<-matrix(1,nrow(xprobval),1)
mestmt74<-cbind(onetemp,xprobval)
if (ncs > 0)
{
ncovmdl<-sum(ccmat[i,])
if (ncovmdl > 0)
{
cvmnc<-matrix(1,nrow(mestmt74),ncovmdl)
cvmnctmp<-t(matrix(apply(matrix(x[,(ncol(x)-ncovmdl+1):ncol(x)],nrow=nrow(x)),2,mean)))
if (cuscoval > 0){cvmnctmp<-coval}
for (mestlp in c(1:ncovmdl))
{cvmnc[,mestlp]<-cvmnc[,mestlp]*cvmnctmp[,mestlp]}
mestmt74<-cbind(mestmt74,cvmnc)
}
}
mest74t<-mestmt74%*%b
if (i==1){mest74<-mest74t}
if (i > 1){mest74<-cbind(mest74,mest74t)}
}
#linear sum
if ((i==(nms+nys)) & (model >= 0) & (model < 4) & (linsum[1,1] != -999))
{
lhyprob<-1;meansub<-0
if (((nlinsum==nrow(b)) | (nlinsum==(nrow(b)-ncs))))
{
if ((nlinsum ==(nrow(b)-ncs)) & (ncs > 0))
{
linsum<-cbind(linsum,covmeans)
meansub<-1
}
lhyprob<-0;hypest<-linsum%*%b
sehypest<-sqrt(linsum%*%varb%*%t(linsum))
phypest<-2*(pt((-abs(hypest/sehypest)),dfres))
hypest<-matrix(c(hypest,sehypest,(hypest/sehypest),phypest,(hypest-tval*sehypest),(hypest+tval*sehypest)),ncol=6)
resultm2<-matrix(99999,ncol(linsum),maxresm)
resultm2[,1]<-t(linsum)
resultm<-rbind(resultm,resultm2)
resultm2<-matrix(99999,1,maxresm)
resultm2[1,1:ncol(hypest)]<-hypest
resultm<-rbind(resultm,resultm2)
if (outscreen==1)
{
hyplabs<-c("Estimate",hclab,"t","p","LLCI","ULCI")
cat("\n----------\n")
cat("Linear Combination Estimate and Hypothesis Test\n")
linsumpt<-noquote(matrix(sprintf(decimals,linsum),ncol=1))
colnames(linsumpt)<-"weight"
rownames(linsumpt)<-vlabsm
cat("\nWeight vector:\n")
print(linsumpt,right=TRUE)
hypestpt<-noquote(matrix(sprintf(decimals,hypest),ncol=6))
colnames(hypestpt)<-hyplabs
rownames(hypestpt)<-" "
cat("\n")
print(hypestpt,right=TRUE)
if (meansub==1)
{cat("\nCovariate weight(s) set to the sample mean.\n")}
}
}
if (lhyprob==1){notecode[notes,1]<-30;notes<-notes + 1}
}
}
#END G LOOP
lastb<-b
lastcov<-varb
if ((criterr==0) & (dototal==1))
{
x<-xtmp
vlabsm<-matrix(c("constant",xcatlab[1:nxvls,1]))
if (ncs > 0)
{
x<-cbind(as.matrix(x),as.matrix(ctmp))
vlabsm<-matrix(c(vlabsm,t(covnames)))
}
x<-cbind(ones,x)
modoutz<-process.modelest(y,x,1,1,xp2,hc)
modsum<-matrix(unlist(modoutz[3]))
modres<-matrix(unlist(modoutz[1]),nrow=ncol(x))
toteff<-matrix(modres,nrow=ncol(x))
toteff<-matrix(toteff[2:(1+nxvls),],nrow=nxvls)
nodotot<-0
if ((xdich==1) & (xmint==1) & (model==74))
{
toteff[,1]<-toteff[,1]*xscaling
toteff[,2]<-toteff[,2]*abs(xscaling)
toteff[,3]<-toteff[,3]*xscaling
toteff[,5]<-toteff[,5]*xscaling
toteff[,6]<-toteff[,6]*xscaling
citmp<-t(matrix(toteff[,5:6]))
if (xscaling < 0)
{
toteff[,5]<-citmp[,2]
toteff[,6]<-citmp[,1]
}
nodotot<-1
}
if (outscreen==1)
{
if (nodotot==0)
{cat("\n************************ TOTAL EFFECT MODEL *************************** \n")}
if (nodotot==1)
{cat("\n*********************************************************************** \n")}
cat("Outcome Variable: ")
write.table(outnames[nrow(outnames),1],quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
}
resultm2<-matrix(99999,1,maxresm)
resultm2[1,1:nrow(modsum)]<-t(modsum)
resultm<-rbind(resultm,resultm2)
modsum<-noquote(matrix(sprintf(decimals,modsum),nrow=1))
resultm2<-matrix(99999,nrow(modres),maxresm)
resultm2[1:nrow(modres),1:ncol(modres)]<-modres
resultm<-rbind(resultm,resultm2)
modres<-noquote(matrix(sprintf(decimals,modres),nrow=ncol(x)))
varb<-matrix(unlist(modoutz[6]),nrow=ncol(x))
brsq2<-modsum[1,2]
b<-matrix(unlist(modoutz[5]))
colnames(modsum)<-modsuml;rownames(modsum)<-" "
rownames(modres)<-vlabsm;colnames(modres)<-modresl
if (outscreen==1)
{
cat("Model Summary: \n")
print(modsum,right=T)
cat("\n")
cat("Model: \n")
print(modres,right=T)
}
totefflb<-modresl
toteffl2<-vlabsm[2:(1+nxvls),]
lmat<-matrix(0,nrow(b),1)
lmat2<-matrix(1,nxvls,1)
lmat[2:(1+nxvls),1]<-lmat2
if (ydich != 1)
{totomni<-process.ftest3(lmat,b,varb,1,brsq2,0,y,x)}
if (stand==1)
{
predsd<-matrix(0,nrow(modres),1)
stdmod<-as.numeric(modres[,1])/ovsd[nrow(ovsd),1]
for (jd in c(1:ncol(x)))
{predsd[jd,1]<-sd(x[,jd])}
if ((wherex[1,ncol(wherex)] != -999) & ((nxvls > 1) | (xdich==1)))
{
sdmsone<-matrix(1,nxvls,1)
predsd[wherex[1,ncol(wherex)]:wherex[2,ncol(wherex)],1]<-sdmsone
pstog<-1
}
predsd[1,1]<-1
stdmod<-stdmod*predsd
stdmod<-matrix(stdmod[2:nrow(stdmod),1])
sdvlabs<-vlabsm[2:nrow(vlabsm),1]
resultm2<-matrix(99999,nrow(stdmod),maxresm)
resultm2[1:nrow(stdmod),1:ncol(stdmod)]<-stdmod
resultm<-rbind(resultm,resultm2)
stdmod<-noquote(matrix(sprintf(decimals,stdmod),(nrow(b)-1)))
colnames(stdmod)<-"coeff"
rownames(stdmod)<-sdvlabs
if (outscreen==1)
{cat("\nStandardized coefficients:\n")
print(stdmod,right=T)}
}
if (covcoeff==1)
{
varbpr<-noquote(matrix(sprintf(decimals,varb),nrow=nrow(b)))
rownames(varbpr)<-vlabsm;colnames(varbpr)<-vlabsm
if (outscreen==1)
{
cat("\nCovariance matrix of regression parameter estimates:\n")
print(varbpr,right=T)
resultm2<-matrix(99999,nrow(varb),maxresm)
if (ncol(varb) <= maxresm)
{
resultm2[1:nrow(varb),1:ncol(varb)]<-varb
resultm<-rbind(resultm,resultm2)
}
if (ncol(varb) > maxresm)
{
resultmt<-matrix(99999,nrow(resultm),ncol(varb))
resultmt[1:nrow(resultm),1:ncol(resultm)]<-resultm
resultm<-resultmt
resultm2<-matrix(99999,nrow(varb),ncol(resultm))
resultm2[1:nrow(varb),1:ncol(varb)]<-varb
resultm<-rbind(resultm,resultm2)
maxresm<-ncol(resultm)
}
}
}
}
}
#END cycle through the models
if ((criterr==0) & (nms > 0) & (ydich==0) & (modelres==1))
{
modresid<-matrix(modresid[,2:ncol(modresid)],ncol=(ncol(modresid)-1))
corall<-cor(modresid)
resultm2<-matrix(99999,nrow(corall),maxresm)
resultm2[1:nrow(corall),1:ncol(corall)]<-corall
resultm<-rbind(resultm,resultm2)
corall2<-noquote(matrix(sprintf(decimals,corall),nrow=nrow(corall)))
colnames(corall2)<-outnames
rownames(corall2)<-outnames
if (outscreen==1)
{cat("\n*************** CORRELATIONS BETWEEN MODEL RESIDUALS **************** \n\n")
print(corall2,right=T)}
}
#DO BOOTSTRAPPING
if ((criterr==0) & (boot > 0))
{
bootres<-matrix(-999,1,sum(nump))
bootdir<-obsdirfx
natdirbt<-matrix(-999,1,nxvls)
if (effsize==1){bootysd<-matrix(-999,1,1);bootxsd<-matrix(-999,1,1)}
badboot<-0;goodboot<-0;smallest<-1;booting<-1
j<-1
if (outscreen==1)
{
cat("\n*********************************************************************** \n")
if (progress==1)
{cat("Bootstrapping progress:\n")
bootprog<-txtProgressBar(min=0,max=boot,char=">",width=62,style=3)}
if (progress !=1){cat("Bootstrapping in progress. Please wait.\n");flush.console()}
}
while ((goodboot < boot) & (j <= maxboot))
{
if ((outscreen==1) & (progress==1)){setTxtProgressBar(bootprog,j)}
nobootx<-1;modres2<-999;bad<-0;
v<-as.matrix(trunc(runif(n)*n)+1)
for (i in (1:(nms+nys)))
{
y<-as.matrix(outvars[v,i])
ynovar<-sum((y-(sum(y)/nrow(y)))*(y-(sum(y)/nrow(y))))
if (ynovar==0){bad<-1}
xindx<-datindx[1:(nump[1,i]-1),i]
hello<-0
x<-as.matrix(fulldat[v,xindx])
x<-cbind(ones,x)
xsq<-t(x)%*%x
exsq<-eigen(xsq)
exsq<-matrix(unlist(exsq[1]))
holymoly<-min(exsq)
zeroeig<-sum(as.numeric(exsq <= 0.000000000002))
bad<-bad+as.numeric(zeroeig > 0)
bad=bad+as.numeric(sd(y)==0)
if (bad==0)
{
if (holymoly < smallest){smallest<-holymoly}
if ((ydich==0) | (i < (nms+nys)))
{modrest<-process.modelest(y,x,type=1,full=0,xp2,hc)}
if ((ydich==1) & (i==(nms+nys)))
{modrest<-process.modelest(y,x,3,0,xp2,hc,iterate,converge)}
modres2<-as.matrix(c(modres2,modrest))
if (i==(nms+nys))
{
if (bcmat[(i+1),1]==1)
{bootdir<-rbind(bootdir,t(modrest[wherex[1,i]:wherex[2,i],1]))}
if (bcmat[(i+1),1]==0)
{bootdir<-rbind(bootdir,dirzes)}
}
if ((model==74) & (i <= nms))
{
onetemp<-matrix(1,nrow(xprobval),1)
mestmtb<-cbind(onetemp,xprobval)
if (ncs > 0)
{
ncovmdlb<-sum(ccmat[i,])
if (ncovmdl > 0)
{
cvmncb<-matrix(1,nrow(mestmtb),ncovmdlb)
cvmnctmp<-t(matrix(apply(matrix(x[,(ncol(x)-ncovmdl+1):ncol(x)],nrow=nrow(x)),2,mean)))
if (cuscoval > 0){cvmnctmp<-coval}
for (mestlp in c(1:ncovmdlb))
{cvmncb[,mestlp]<-cvmncb[,mestlp]*cvmnctmp[,mestlp]}
mestmtb<-cbind(mestmtb,cvmncb)
}
}
mestbt<-mestmtb%*%modrest
if (i == 1){mestb<-mestbt}
if (i > 1){mestb<-cbind(mestb,mestbt)}
}
if ((model==74) & (i==(nms+nys)))
{
xvalptmp<-matrix(0,1,nxvls)
mest74sp<-matrix(0,1,nms)
mest74sp<-rbind(mest74sp,mestb)
xvalptmp<-rbind(xvalptmp,diag(nxvls))
dirfxcf<-matrix(0,nrow(mestb),1)
for (cfloop1 in (1:nrow(mestb)))
{
ndirfx<-matrix(0,nrow(modrest),1)
ndirfx[2:(nxvls+1),1]<-t(xvalptmp[cfloop1,])
for (cfloop3 in (1:nms))
{
if ((mcx==1) | (mcx==0))
{ndirfx[wheremw[(1+((cfloop3-1)*2)),ncol(wheremw)]:wheremw[(2+((cfloop3-1)*2)),ncol(wheremw)]]<-t(xvalptmp[cfloop1,]*mestb[1,cfloop3])}
if (mcx==2)
{ndirfx[wheremw[(1+((cfloop3-1)*2)),ncol(wheremw)]:wheremw[(2+((cfloop3-1)*2)),ncol(wheremw)]]<-t(xvalptmp[cfloop1,]*mest74sp[cfloop1,cfloop3])}
}
if (cfloop1 > 1){dirfxcf[cfloop1,1]<-t(ndirfx)%*%modrest*xscaling}
}
natdirbt<-rbind(natdirbt,t(dirfxcf[2:nrow(dirfxcf),]))
}
if ((bcmat[(i+1),1]==1) & (nobootx==1) & (effsize==1))
{
nobootx<-0
xsdtemp<-sum((x[,2]-(sum(x[,2])/nrow(x)))*(x[,2]-(sum(x[,2])/nrow(x))))
xsdtemp<-sqrt(xsdtemp/(nrow(x)-1))
}
}
}
if (bad==0)
{
modres2<-t(modres2[2:nrow(modres2),])
#modres2<-matrix(modres2[,2:nrow(modres2),ncol=ncol(modres)-1)
bootres<-rbind(bootres,modres2)
if (effsize==1)
{
ysdtemp<-sd(y)
bootysd<-rbind(bootysd,ysdtemp)
bootxsd<-rbind(bootxsd,xsdtemp)
}
goodboot<-goodboot+1
}
if (bad != 0){badboot<-badboot+1}
j<-j+1
}
bootres<-as.matrix(bootres[2:nrow(bootres),])
if (effsize==1)
{
bootysd<-matrix(bootysd[2:nrow(bootysd),])
if (nrow(bootxsd) > 1){bootxsd<-matrix(bootxsd[2:nrow(bootxsd)])}
}
if (goodboot < (boot))
{boot<-0;modelbt<-0;notecode[notes,1]<-7;notes<-notes+1}
if (boot > 0)
{
if (effsize==1){bootysd<-rbind(ysd,bootysd);bootxsd<-rbind(xsd,bootxsd)}
if (saveboot==1)
{
savlabs<-matrix(" ",ncol(bootres))
for (i in c(1:ncol(bootres))){savlabs[i,1]<-paste("col",i,sep='')}
boots<-as.data.frame(bootres)
colnames(boots)<-savlabs
#assign("process.boots", boots, envir = .GlobalEnv)
}
if (modelbt==1)
{
bootcim<-matrix(-99999,ncol(bootres),5)
bootcim[,2]<-t(colSums(bootres)/nrow(bootres))
bootcim[,1]<-as.numeric(coeffmat[2:nrow(coeffmat),1])
for (i in (1:ncol(bootres)))
{
if (bc==0){bootcim[i,3:5]<-t(process.pboot3(bootres[,i],cilow,cihigh))}
if (bc==1)
{
bcbout<-process.bcboot3(bootres[,i],bootcim[i,1],xp2,badend,priorlo,priorhi)
bootcim[i,3:5]<-t(matrix(unlist(bcbout[1])))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
}
}
}
if (badboot > 0){notecode[notes,1]<-6;notes<-notes+1}
if ((outscreen==1) & (progress==1)){close(bootprog)}
}
#end of bootstrapping
if ((xmint==1) & (criterr==0))
{
xvalptmp<-matrix(0,1,nxvls)
mest74sp<-matrix(0,1,nms)
mest74sp<-rbind(mest74sp,mest74)
xvalptmp<-rbind(xvalptmp,diag(nxvls))
for (kcfuhd in (1:2))
{
dirfxcf<-matrix(0,nrow(mest74),6)
for (cfloop1 in (1:nrow(mest74)))
{
ndirfx<-matrix(0,nrow(lastb),1)
ndirfx[2:(nxvls+1),1]<-t(xvalptmp[cfloop1,])
for (cfloop3 in (1:nms))
{
if (kcfuhd==1)
{
if ((mcx==1) | (mcx==0))
{ndirfx[wheremw[(1+((cfloop3-1)*2)),ncol(wheremw)]:wheremw[(2+((cfloop3-1)*2)),ncol(wheremw)]]<-t(xvalptmp[cfloop1,]*mest74[1,cfloop3])}
if (mcx==2)
{ndirfx[wheremw[(1+((cfloop3-1)*2)),ncol(wheremw)]:wheremw[(2+((cfloop3-1)*2)),ncol(wheremw)]]<-t(xvalptmp[cfloop1,]*mest74sp[cfloop1,cfloop3])}
}
if (kcfuhd==2)
{ndirfx[wheremw[(1+((cfloop3-1)*2)),ncol(wheremw)]:wheremw[(2+((cfloop3-1)*2)),ncol(wheremw)]]<-t(xvalptmp[cfloop1,]*medmeans[1,cfloop3])}
}
if (cfloop1 > 1)
{
dirfxcf[cfloop1,1]<-t(ndirfx)%*%lastb*xscaling
dirfxcf[cfloop1,2]<-sqrt(diag(t(ndirfx)%*%lastcov%*%ndirfx))*abs(xscaling)
dirfxcf[cfloop1,3]<-dirfxcf[cfloop1,1]/dirfxcf[cfloop1,2]
dirfxcf[cfloop1,4]<-2*pt(-abs(dirfxcf[cfloop1,3]),df=dfres)
dirfxcf[cfloop1,5]<-dirfxcf[cfloop1,1]-tval*dirfxcf[cfloop1,2]
dirfxcf[cfloop1,6]<-dirfxcf[cfloop1,1]+tval*dirfxcf[cfloop1,2]
}
}
codireff<-matrix(dirfxcf[2:nrow(dirfxcf),],nrow=(nrow(dirfxcf)-1))
if (kcfuhd==1){direff<-codireff}
}
}
#Here is for the indirect effects
if ((criterr==0) & (nms > 0))
{
paths<-matrix(paths[,2:ncol(paths)],nrow=nrow(paths))
pathsw<-matrix(pathsw[,2:ncol(pathsw)],nrow=nrow(pathsw))
pathsz<-matrix(pathsz[,2:ncol(pathsz)],nrow=nrow(pathsz))
pathswz<-matrix(pathswz[,2:ncol(pathswz)],nrow=nrow(pathswz))
pathsmod<-pathsw+pathsz+pathswz
pathsdv<-t(pathsdv[2:nrow(pathsdv),])
pathsfoc<-matrix(pathsfoc[,2:ncol(pathsfoc)],nrow=nrow(pathsfoc))
pathtype<-matrix(pathtype[,2:ncol(pathtype)],nrow=nrow(pathtype))
anymod<-as.numeric(sum(pathsmod) > 0)
obscoeff<-t(as.matrix(obscoeff[1,2:ncol(obscoeff)]))
if (outscreen==1)
{
if (xmint==1)
{cat("\n********************** COUNTERFACTUALLY DEFINED ***********************")}
if ((dototal==0) & (alttotal==0))
{cat("\n**************** DIRECT AND INDIRECT EFFECTS OF X ON Y ****************\n")}
if (alttotal==1)
{cat("\n************ TOTAL, DIRECT AND INDIRECT EFFECTS OF X ON Y *************\n")}
}
if (dototal==1)
{
if (outscreen==1)
{cat("\n************ TOTAL, DIRECT, AND INDIRECT EFFECTS OF X ON Y ************\n")}
totefflb[1,1]<-"effect"
if (effsize==1)
{
toteffsz<-toteff[,1]/ysd
if ((xdich==1) | (mcx > 0)){totefflb<-cbind(totefflb,"c_ps")}
if ((xdich==0) & (mcx==0))
{toteffsz<-(toteffsz*xsd);totefflb<-cbind(totefflb,"c_cs")}
toteff<-cbind(toteff,toteffsz)
}
resultm2<-matrix(99999,nrow(toteff),maxresm)
resultm2[1:nrow(toteff),1:ncol(toteff)]<-toteff
resultm<-rbind(resultm,resultm2)
toteff2<-noquote(matrix(sprintf(decimals,toteff),nrow=nrow(toteff)))
colnames(toteff2)<-totefflb
if (nxvls > 1)
{
rownames(toteff2)<-toteffl2
if (outscreen==1)
{cat("\nRelative total effects of X on Y:\n")
print(toteff2,right=T)}
clabtmp<-c("R2-chng", hcflab, "df1","df2","p")
resultm2<-matrix(99999,nrow(totomni),maxresm)
resultm2[1:nrow(totomni),1:ncol(totomni)]<-totomni
resultm<-rbind(resultm,resultm2)
totomni2<-noquote(matrix(sprintf(decimals,totomni),nrow=nrow(totomni)))
colnames(totomni2)<-clabtmp
rownames(totomni2)<-" "
if (outscreen==1)
{
cat("\nOmnibus test of total effect of X on Y:\n")
print(totomni2,right=T)
cat("----------\n")
}
}
if (nxvls < 2)
{
rownames(toteff2)<-" "
if (outscreen==1)
{cat("\nTotal effect of X on Y:\n")
print(toteff2,right=T)}
}
}
moddir<-wcmat[nrow(bcmat),1]+zcmat[nrow(bcmat),1]
if (xmint==1){moddir<-1}
if (bcmat[nrow(bcmat),1]==1)
{
if (ydich==1)
{
direfflb[,(ncol(direfflb)-5):ncol(direfflb)]<-t(matrix(c("Effect","se","Z","p","LLCI","ULCI")))
}
if ((moddir==0) | (xmint==1)){direfflb[1,1]="effect"}
if ((effsize==1) & (moddir==0) & (anymod == 0))
{
direffsz<-direff[,1]/ysd
if ((xdich==1) | (mcx > 0)){direfflb<-cbind(direfflb,"c'_ps")}
if ((xdich==0) & (mcx==0))
{direffsz<-(direffsz*xsd);direfflb<-cbind(direfflb,"c'_cs")}
direff<-cbind(direff,direffsz)
}
resultm2<-matrix(99999,nrow(direff),maxresm)
resultm2[1:nrow(direff),1:ncol(direff)]<-direff
resultm<-rbind(resultm,resultm2)
if (xmint==1)
{
resultm2<-matrix(99999,nrow(codireff),maxresm)
resultm2[1:nrow(codireff),1:ncol(codireff)]<-codireff
resultm<-rbind(resultm,resultm2)
}
direff2<-noquote(matrix(sprintf(decimals,direff),nrow=nrow(direff)))
colnames(direff2)<-direfflb
if ((moddir==0) & (nxvls==1) & (outscreen==1))
{
rownames(direff2)<-" "
cat("\nDirect effect of X on Y:\n")
print(direff2,right=T)
}
if ((moddir==0) & (nxvls>1))
{
rownames(direff2)<-direffl2
if (outscreen==1)
{cat("\nRelative direct effects of X on Y:\n")
print(direff2,right=T)}
resultm2<-matrix(99999,nrow(diromni),maxresm)
resultm2[1:nrow(diromni),1:ncol(diromni)]<-diromni
resultm<-rbind(resultm,resultm2)
diromni2<-noquote(matrix(sprintf(decimals,diromni),nrow=nrow(diromni)))
rownames(diromni2)<-" "
if (ydich==0)
{
colnames(diromni2)<-c("R2-chng", hcflab, "df1","df2","p")
if (outscreen==1)
{cat("\nOmnibus test of direct effect of X on Y:\n")
print(diromni2,right=T)}
}
if (ydich==1)
{
colnames(diromni2)<-c("Chi-sq", "df", "p")
if (outscreen==1)
{cat("\nOmnibus likelihood ratio test of direct effect of X on Y:\n")
print(diromni2,right=T)}
}
if (outscreen==1)
{cat("\n----------\n")}
}
if ((moddir > 0) & (nxvls==1))
{
if ((xmint==0) & (outscreen==1))
{cat("\nConditional direct effect(s) of X on Y:\n")}
if ((xmint==1) & (outscreen==1))
{
cat("\n(Pure) Natural direct effect of X on Y:\n")
}
if (xmint==1){obnatdfx<-matrix(direff[,1],nrow=nrow(direff))}
rownames(direff2)<-t(matrix(replicate(nrow(direff2)," ")))
if (outscreen==1){print(direff2,right=T)}
if (xmint==1)
{
if ((outscreen==1) & (xmint==1))
{
cat("\nControlled direct effect of X on Y:\n")
codiref2<-noquote(matrix(sprintf(decimals,codireff),nrow=nrow(codireff)))
rownames(codiref2)<-t(matrix(replicate(nrow(codireff)," ")))
colnames(codiref2)<-direfflb
print(codiref2,right=T)
cat("\n----------\n")
}
}
}
direffl4<-direffl2
if ((moddir > 0) & (nxvls>1))
{
direffl2=" "
for (i in (1:nxvls))
{
for (j in (1:(nrow(direff)/nxvls)))
{direffl2<-rbind(direffl2,xcatlab[i,1])}
}
direffl2<-direffl2[2:nrow(direffl2),1]
rownames(direff2)<-direffl2
if ((xmint==0) & (outscreen==1))
{cat("\nRelative conditional direct effects of X on Y:\n")}
if ((xmint==1) & (outscreen==1))
{
cat("\nRelative (pure) natural direct effects of X on Y:\n")
}
if (outscreen==1){print(direff2,right=T)}
if (xmint==1){obnatdfx<-matrix(direff[,1],nrow=nrow(direff))}
if ((xmint==1) & (outscreen==1))
{
cat("\nRelative controlled direct effects of X on Y:\n")
codiref2<-noquote(matrix(sprintf(decimals,codireff),nrow=nrow(codireff)))
rownames(codiref2)<-direffl2
colnames(codiref2)<-direfflb
print(codiref2,right=T)
cat("\n----------\n")
}
}
direffl2<-direffl4
}
if ((bcmat[nrow(bcmat),1]==0) & (xmint != 1) & (outscreen==1))
{cat("\nThe direct effect of X on Y is fixed to zero.\n")}
#Here is the start of the indirect effects
if (nms==1){indmark<-matrix(2);indsets<-t(matrix(c(1,2)))}
if (nms==2){indmark<-t(matrix(c(2,2,3)));indsets<-t(matrix(c(1,4,2,5,1,3,5)));thetam<-matrix(1)}
if (nms==3)
{indmark<-t(matrix(c(2,2,2,3,3,3,4)))
indsets<-t(matrix(c(1,7,2,8,4,9,1,3,8,1,5,9,2,6,9,1,3,6,9)))
thetam<-t(matrix(c(1,2,3)))}
if (nms==4)
{indmark<-t(matrix(c(2,2,2,2,3,3,3,3,3,3,4,4,4,4,5)))
indsets<-t(matrix(c(1,11,2,12,4,13,7,14,1,3,12,1,5,13,1,8,14,2,6)))
indsets<-cbind(indsets,t(matrix(c(13,2,9,14,4,10,14,1,3,6,13,1,3,9,14,1,5,10,14,2,6,10,14,1,3,6,10,14))))
thetam<-t(matrix(c(1,2,4,3,5,6)))}
if (nms==5)
{indmark<-t(matrix(c(2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,6)))
indsets<-t(matrix(c(1,16,2,17,4,18,7,19,11,20,1,3,17,1,5,18,1,8,19,1,12,20,2,6,18,2,9,19,2)))
indsets<-cbind(indsets,t(matrix(c(13,20,4,10,19,4,14,20,7,15,20,1,3,6,18,1,3,9,19,1,3,13,20,1,5,10))))
indsets<-cbind(indsets,t(matrix(c(19,1,5,14,20,1,8,15,20,2,6,10,19,2,6,14,20,2,9,15,20,4,10,15,20,1))))
indsets<-cbind(indsets,t(matrix(c(3,6,10,19,1,3,6,14,20,1,3,9,15,20,1,5,10,15,20,2,6,10,15,20,1,3))))
indsets<-cbind(indsets,t(matrix(c(6,10,15,20))))
thetam<-t(matrix(c(1,2,5,3,6,8,4,7,9,10)))}
if (nms==6)
{indmark<-t(matrix(c(2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5)))
indmark<-cbind(indmark,t(matrix(c(5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,7))))
indsets<-t(matrix(c(1,22,2,23,4,24,7,25,11,26,16,27,1,3,23,1,5,24,1,8,25,1,12,26,1,17,27,2,6,24,2,9,25,2,13,26,2,18)))
indsets<-cbind(indsets,t(matrix(c(27,4,10,25,4,14,26,4,19,27,7,15,26,7,20,27,11,21,27,1,3,6,24,1,3,9,25,1,3,13,26,1,3))))
indsets<-cbind(indsets,t(matrix(c(18,27,1,5,10,25,1,5,14,26,1,5,19,27,1,8,15,26,1,8,20,27,1,12,21,27,2,6,10,25,2,6,14,26))))
indsets<-cbind(indsets,t(matrix(c(2,6,19,27,2,9,15,26,2,9,20,27,2,13,21,27,4,10,15,26,4,10,20,27,4,14,21,27,7,15,21,27))))
indsets<-cbind(indsets,t(matrix(c(1,3,6,10,25,1,3,6,14,26,1,3,6,19,27,1,3,9,15,26,1,3,9,20,27,1,3,13,21,27,1,5,10,15,26))))
indsets<-cbind(indsets,t(matrix(c(1,5,10,20,27,1,5,14,21,27,1,8,15,21,27,2,6,10,15,26,2,6,10,20,27,2,6,14,21,27,2,9,15))))
indsets<-cbind(indsets,t(matrix(c(21,27,4,10,15,21,27,1,3,6,10,15,26,1,3,6,10,20,27,1,3,6,14,21,27,1,3,9,15,21,27,1,5,10))))
indsets<-cbind(indsets,t(matrix(c(15,21,27,2,6,10,15,21,27,1,3,6,10,15,21,27))))
thetam<-t(matrix(c(1,2,6,3,7,10,4,8,11,13,5,9,12,14,15)))}
if (nms==7)
{indmark<-t(matrix(c(2,2,2,2,2,2,2)));indsets<-t(matrix(c(1,29,2,30,4,31,7,32,11,33,16,34,22,35)))}
if (nms==8)
{indmark<-t(matrix(c(2,2,2,2,2,2,2,2)));indsets<-t(matrix(c(1,37,2,38,4,39,7,40,11,41,16,42,22,43,29,44)))}
if (nms==9)
{indmark<-t(matrix(c(2,2,2,2,2,2,2,2,2)));indsets<-t(matrix(c(1,46,2,47,4,48,7,49,11,50,16,51,22,52,29,53,37,54)))}
if (nms==10)
{indmark<-t(matrix(c(2,2,2,2,2,2,2,2,2,2)))
indsets<-t(matrix(c(1,56,2,57,4,58,7,59,11,60,16,61,22,62,29,63,37,64,46,65)))}
indlbl<-"Ind1"
for (indb in (2:90))
{indlbl<-cbind(indlbl,paste("Ind",indb,sep=''))}
indlbl<-matrix(indlbl)
cntname<-"(C1)"
for (indb in (2:105))
{cntname<-cbind(cntname,paste("(C",indb,")",sep=''))}
cntname<-matrix(cntname)
indmake<-matrix(0,ncol(indmark),(nms+2))
indmod<-matrix(999,ncol(indmark),1)
indmmm<-matrix(0,ncol(indmark),1)
indmmmt<-matrix(0,ncol(indmark),1)
start<-1;end<-0;nindfx<-0
indlocs<-matrix(999,nrow(thetaxmb),ncol(paths))
indkey<-matrix(" ",ncol(indmark),1+((max(indmark)*2)+1))
c1<-1;c2<-1;c3<-1
for (i in (1:ncol(paths)))
{
if (pathtype[1,i]==1){indlocs[,i]<-thetaxmb[,c1];c1<-(c1+1)}
if (pathtype[1,i]==3){indlocs[,i]<-thetamyb[,c2];c2<-(c2+1)}
if ((pathtype[1,i]==2) & (nms < 7) & (serial==1)){indlocs[,i]<-thetammb[,thetam[1,c3]];c3<-(c3+1)}
}
for (i in (1:ncol(indlocs)))
{
c1<-2
for (j in (2:nrow(indlocs)))
{
if (indlocs[j,i] != 0){indlocs[c1,i]<-indlocs[j,i];c1<-(c1+1)}
}
indlocs[1,i]<-(c1-2)
}
indlocs<-indlocs[1:max((indlocs[1,])+1),]
for (i in (1:ncol(indmark)))
{
numget<-indmark[1,i];end<-end+numget;gotcha<-t(matrix(indsets[1,start:end]))
start<-end+1;ok<-1;temp<-0;repoman<-matrix(0,4,1)
for (j in (1:ncol(gotcha)))
{
if (paths[1,gotcha[1,j]]==0){ok<-0}
if (pathsmod[1,gotcha[1,j]] > 0)
{
temp<-1
temp2<-rbind(pathsw[1,gotcha[1,j]],pathsz[1,gotcha[1,j]],pathswz[1,gotcha[1,j]],0)
temp2<-matrix(temp2)
if ((temp2[1,1]==1) & (temp2[2,1]==1) & (temp2[3,1]==0)){temp2[4,1]<-1}
repoman<-repoman+temp2
}
}
temp<-0;tempmmm<-0;typemmm<-0
if ((repoman[1,1] > 0) & (repoman[2,1]==0))
{
temp<-1
if (repoman[1,1]==1){tempmmm<-1}
if ((repoman[1,1] > 1) & ((wdich==1) | (mcw > 0)))
{
tempmmm<-12;typemmm<-mcw
if (wdich==1){typemmm<-1}
}
if ((repoman[1,1] > 1) & ((wdich==0) & (mcw==0))){tempmmm<-101}
}
if ((repoman[1,1]==0) & (repoman[2,1] > 0))
{
temp<-2
if (repoman[2,1]==1){tempmmm<-2}
if ((repoman[2,1] > 1) & ((zdich==1) | (mcz > 0)))
{
tempmmm<-22;typemmm<-mcz
if (zdich==1){typemmm<-1}
}
if ((repoman[2,1] > 1) & ((zdich==0) & (mcw==0))){tempmmm<-102}
}
if ((repoman[1,1] > 0) & (repoman[2,1] > 0))
{
temp<-3
if ((repoman[1,1]==1) & (repoman[2,1]==1))
{
if (repoman[4,1]==1){tempmmm<-31}
if (repoman[3,1]==1){tempmmm<-41}
}
}
if ((repoman[1,1]==1) & (repoman[2,1]==1) & (repoman[3,1]==0) & (repoman[4,1]==0)){tempmmm<-51}
if (ok==1)
{
nindfx<-nindfx+1
indmake[nindfx,1]<-numget;indmod[nindfx,1]<-temp;indmmm[nindfx,1]<-tempmmm
indmmmt[nindfx,1]<-typemmm;indmake[nindfx,2:(1+numget)]<-gotcha;indkey[nindfx,1]<-xnames
for (j in (1:numget))
{
indkey[nindfx,(j*2+1)]<-pathsdv[1,gotcha[1,j]]
indkey[nindfx,(j*2)]<-" -> "
}
}
}
indkey<-matrix(indkey[1:nindfx,1:((max(indmake[,1])*2)+1)],nrow=nindfx)
indmake<-matrix(indmake[1:nindfx,1:(max(indmake[,1])+1)],ncol=(max(indmake[,1])+1))
indmod<-as.matrix(indmod[1:nrow(indmake),1])
indmmm<-as.matrix(indmmm[1:nrow(indmake),1])
indmmmt<-as.matrix(indmmmt[1:nrow(indmake),1])
ncpairs<-(((nindfx)*(nindfx-1))/2)
if (((contrast==1) | (contrast==2)) & (ncpairs > 105))
{contrast<-0;notecode[notes,1]<-13;notes<-notes+1}
if (contrast==3)
{
if (ncol(contvec) != nindfx)
{contrast<-0;notecode[notes,1]<-14;notes<-notes+1}
}
#This is for models with no moderator */
if (anymod==0)
{
if ((nms==1) & (contrast > 0)){contrast<-0}
efloop<-(((1-as.numeric(effsize==0))*2)+1)-((((mcx>0) | (xdich==1)))*(1-as.numeric(effsize==0)))
for (kk in (1:efloop))
{
if (boot==0)
{
bootres<-obscoeff
if (kk==1){totbtvec<-matrix(0,1,nxvls)}
indtab<-matrix(999);inddiff<-matrix(999);bootysd<-matrix(ysd);bootxsd<-matrix(xsd)
}
if (boot > 0)
{
bootres<-rbind(obscoeff,bootres)
if (kk==1){totbtvec<-matrix(0,nrow(bootres),nxvls)}
indtab<-matrix(999,1,4);inddiff<-matrix(999,nrow(bootres))
}
indtotal<-matrix(0,nrow(bootres),1)
for (i in (1:nrow(indmake)))
{
for (j in (1:nxvls))
{
indtemp<-matrix(1,nrow(bootres),1)
for (k in (1:indmake[i,1]))
{
jtemp<-1
if ((j > 1) & (k==1)){jtemp<-j}
indtemp<-indtemp*bootres[,pathsfoc[jtemp,indmake[i,(k+1)]]]
}
if (kk==2){indtemp<-indtemp/bootysd}
if (kk==3){indtemp<-((bootxsd*indtemp)/bootysd)}
if (contrast != 0){inddiff<-cbind(inddiff,indtemp)}
if (nxvls==1){indtotal<-(indtotal+indtemp)}
indeff<-indtemp[1,1]
if (kk==1){totbtvec[,j]<-totbtvec[,j]+indtemp}
if (boot > 0)
{
if (bc==0){bcitmp<-process.pboot3(indtemp[2:nrow(indtemp),1],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(indtemp[2:nrow(indtemp),1],indtemp[1,1],xp2,badend,priorlo,priorhi)
bcitmp<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indeff<-cbind(indeff,t(bcitmp))
}
if (kk==1){indtabn<-rbind(indtab,indeff)}
indtab<-rbind(indtab,indeff)
}
}
indtab<-matrix(indtab[2:nrow(indtab),],nrow=(nrow(indtab)-1))
if (kk==1){indtabn<-matrix(indtabn[2:nrow(indtabn),],nrow=(nrow(indtabn)-1))}
rowlbs<-matrix(indlbl[1:nrow(indtab),1])
rowbls3<-rowlbs
if (mc > 0)
{
inddiff<-matrix(-999,mc,1)
indtab2<-matrix(-999,nrow(indtab),4)
indtab2[,1]<-indtab;indtab<-indtab2;mcct<-0
indtotal<-matrix(0,mc,1)
if (kk==1)
{
x1<-sqrt(-2*log(matrix(runif(mc*nrow(mcsopath)),mc,nrow(mcsopath))))*cos((2*3.14159265358979)*matrix(runif(mc*nrow(mcsopath)),mc,nrow(mcsopath)))
x1<-x1%*%chol(indcov)
for (ii in (1:nrow(x1))){x1[ii,]<-(x1[ii,]+t(mcsopath))}
}
for (ii in (1:nms))
{
tmpb<-x1[,((nms*nxvls)+ii)];tmpb2<-tmpb
if (nxvls > 1)
{
for (jj in (1:(nxvls-1)))
{tmpb2<-cbind(tmpb2,tmpb)}
}
indtemp<-as.matrix(x1[,(((ii-1)*nxvls)+1):(ii*nxvls)]*tmpb2)
for (jj in (1:ncol(indtemp)))
{
if (kk==2){indtemp[,jj]<-indtemp[,jj]/ysd}
if (kk==3){indtemp[,jj]<-(xsd*indtemp[,jj])/ysd}
mcicon<-process.pboot3(indtemp[,jj],cilow,cihigh)
mcct<-mcct+1
indtab[mcct,2:4]<-t(mcicon)
}
if (nxvls==1)
{
indtotal<-indtotal+indtemp
if (contrast != 0){inddiff=cbind(inddiff,indtemp)}
}
}
}
if ((normal==1) & (sobelok==1))
{
sobelmat<-matrix(indtab[,1])
sobelmat<-cbind(sobelmat,(sobelmat/2),sobelmat,sobelmat)
for (ii in (1:nms))
{
se2b<-(indcov[((nms*nxvls)+ii),((nms*nxvls)+ii)])
bpath2<-(mcsopath[((nms*nxvls)+ii),1])^2
se2a<-matrix(diag(matrix(indcov[(((ii-1)*nxvls)+1):(ii*nxvls),(((ii-1)*nxvls)+1):(ii*nxvls)],nrow=nxvls)))
apath2<-matrix(mcsopath[(((ii-1)*nxvls)+1):(ii*nxvls),1])^2
sesobel<-sqrt(apath2*se2b+bpath2*se2a+se2a*se2b)
sobelmat[(((ii-1)*nxvls)+1):(ii*nxvls),2]<-sesobel
}
sobelmat[,3]<-sobelmat[,1]/sobelmat[,2]
sobelmat[,4]<-2*(1-pnorm(abs(sobelmat[,3])))
}
if (serial==0){rowlbs<-t(mnames)}
if ((nxvls==1) & (nms > 1))
{
rowlbs<-rbind("TOTAL",rowlbs)
indtemp<-indtotal[1,1]
if ((boot > 0) & (nxvls==1))
{
if (bc==0){bcitmp<-process.pboot3(indtotal[2:nrow(indtotal),1],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(indtotal[2:nrow(indtotal),1],indtotal[1,1],xp2,badend,priorlo,priorhi)
bcitmp<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indtemp<-cbind(indtemp,t(bcitmp))
}
if (mc > 0)
{
obtmc<-indtab[,1];indtemp<-sum(obtmc)
mcicon2<-process.pboot3(indtotal[,1],cilow,cihigh)
indtemp<-cbind(indtemp,t(mcicon2))
}
indtab<-rbind(indtemp,indtab)
}
bootlbs<-"Effect"
if (boot > 0){bootlbs<-c("Effect","BootSE","BootLLCI","BootULCI")}
if (mc > 0){bootlbs<-c("Effect","MC SE","MC LLCI","MC ULCI")}
if (nxvls==1)
{
if (contrast != 0)
{
inddiff<-matrix(inddiff[,2:ncol(inddiff)],nrow=nrow(inddiff))
if (mc > 0){inddiff=rbind(t(obtmc),inddiff)}
if (contrast==3)
{
inddifft<-matrix(inddiff%*%t(contvec))
indtemp<-inddifft[1,1]
if ((boot > 0) | (mc > 0))
{
if ((mc > 0) | ((boot > 0) & (bc==0)))
{bcicon<-process.pboot3(inddifft[2:nrow(inddifft),1],cilow,cihigh)}
if ((boot > 0) & (bc==1))
{
bcbout<-process.bcboot3(inddifft[2:nrow(inddifft),1],inddifft[1,1],xp2,badend,priorlo,priorhi)
bcicon<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indtemp<-cbind(indtemp,t(bcicon))
}
indtab<-rbind(indtab,indtemp)
}
if ((contrast==1) | (contrast==2))
{
conkey<-matrix(" ",1,4)
for (i in (1:(ncol(inddiff)-1)))
{
for (j in ((i+1):ncol(inddiff)))
{
inddifft<-matrix(inddiff[,i]-inddiff[,j])
if (contrast==2){inddifft<-matrix(abs(inddiff[,i])-abs(inddiff[,j]))}
indtemp<-inddifft[1,1]
conkeyt<-cbind(" ", rowlbs[(i+1),1]," minus ",rowlbs[(j+1),1])
conkey<-rbind(conkey,conkeyt)
if ((boot > 0) | (mc > 0))
{
if ((mc > 0) | ((boot > 0) & (bc==0)))
{bcitmp2<-process.pboot3(inddifft[2:nrow(inddifft),1],cilow,cihigh)}
if ((boot > 0) & (bc==1))
{
bcbout<-process.bcboot3(inddifft[2:nrow(inddifft),1],inddifft[1,1],xp2,badend,priorlo,priorhi)
bcitmp2<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indtemp<-cbind(indtemp,t(bcitmp2))
}
indtab<-rbind(indtab,indtemp)
}
}
}
if (contrast != 3)
{contlbs<-matrix(cntname[1:(((nindfx)*(nindfx-1))/2),1])}
if (contrast==3)
{contlbs<-matrix("(C1)")}
rowlbs<-rbind(rowlbs,contlbs)
}
resultm2<-matrix(99999,nrow(indtab),maxresm)
resultm2[1:nrow(indtab),1:ncol(indtab)]<-indtab
resultm<-rbind(resultm,resultm2)
indtab5<-noquote(matrix(sprintf(decimals,indtab),nrow=nrow(indtab)))
colnames(indtab5)<-bootlbs
rownames(indtab5)<-rowlbs
if (outscreen==1)
{
if (kk==1)
{
cat("\nIndirect effect(s) of X on Y:\n")
print(indtab5,right=T)
}
if ((kk==2) & ((xdich==1) | (mcx > 0)))
{
cat("\nPartially standardized indirect effect(s) of X on Y:\n")
print(indtab5,right=T)
}
if (kk==3)
{
cat("\nCompletely standardized indirect effect(s) of X on Y:\n")
print(indtab5,right=T)
}
}
if ((normal==1) & (sobelok==1) & (kk==1))
{
sobellab<-c("Effect",hclab,"Z","p")
sobelrlb<-rowlbs
if (nms > 1){sobelrlb<-matrix(rowlbs[2:(1+nms),1])}
resultm2<-matrix(99999,nrow(sobelmat),maxresm)
resultm2[1:nrow(sobelmat),1:ncol(sobelmat)]<-sobelmat
resultm<-rbind(resultm,resultm2)
sobelmt2<-noquote(matrix(sprintf(decimals,sobelmat),nrow=nrow(sobelmat)))
rownames(sobelmt2)<-sobelrlb
colnames(sobelmt2)<-sobellab
if (outscreen==1)
{cat("\nNormal theory test for indirect effect(s):\n")
print(sobelmt2,right=T)}
}
if (contrast != 0)
{
if (((contrast==1) | (contrast==2)) & (kk==efloop))
{
conkey<-matrix(conkey[2:nrow(conkey),],nrow=(nrow(conkey)-1))
if (outscreen==1)
{cat("\nSpecific indirect effect contrast definition(s):\n")
write.table(conkey,quote=FALSE,row.names=contlbs,col.names=FALSE,sep = " ")}
}
if ((contrast==3) & (kk=efloop))
{
crowlbs<-rowlbs[2:(nindfx+1),1]
contvect<-noquote(matrix(sprintf(decimals,contvec),nrow=1))
colnames(contvect)<-crowlbs
rownames(contvect)<-"(C1)"
if (outscreen==1)
{cat("\nSpecific indirect effect contrast weights:\n")
print(contvect,right=T)}
}
if ((contrast==2) & (kk==efloop) & (outscreen==1))
{cat("\nContrasts are differences between absolute values of indirect effects\n")}
}
if ((serial==1) & (kk==efloop))
{rowlbst<-matrix(rowlbs[2:nrow(rowlbs),1],nrow<-(nrow(rowlbs)-1))
if (outscreen==1)
{cat("\nIndirect effect key:\n")
write.table(indkey,quote=FALSE,row.names=rowbls3,col.names=FALSE,sep=" ")}}
}
if (nxvls > 1)
{
if (outscreen==1)
{
if (kk==1){cat("\nRelative indirect effects of X on Y:\n")}
if (kk==2){cat("\nPartially standardized relative indirect effects of X on Y:\n")}
if (kk==3){cat("\nCompletely standardized relative indirect effects of X on Y:\n")}
}
for (i in (1:nrow(indmake)))
{
indtabsm<-indtab[(((i-1)*nxvls)+1):(nxvls*i),]
indkeyt<-indkey[i,]
if (outscreen==1)
{
cat("\n")
write.table(t(indkeyt),quote=FALSE,row.names=FALSE,col.names=FALSE,sep=" ")
cat("\n")
}
if (bcmat[nrow(bcmat),1]==0)
{direffl2<-xcatlab[1:nxvls,1]}
resultm2<-matrix(99999,nrow(indtabsm),maxresm)
resultm2[1:nrow(indtabsm),1:ncol(indtabsm)]<-indtabsm
resultm<-rbind(resultm,resultm2)
indtasm2<-noquote(matrix(sprintf(decimals,indtabsm),nrow=nrow(indtabsm)))
colnames(indtasm2)<-bootlbs
rownames(indtasm2)<-direffl2
if (outscreen==1)
{print(indtasm2,right=T)}
if ((normal==1) & (sobelok==1) & (kk==1))
{
sobelsm=sobelmat[(((i-1)*nxvls)+1):(nxvls*i),]
sobellab=c("Effect",hclab,"Z","p")
resultm2<-matrix(99999,nrow(sobelsm),maxresm)
resultm2[1:nrow(sobelsm),1:ncol(sobelsm)]<-sobelsm
resultm<-rbind(resultm,resultm2)
sobelsm2<-noquote(matrix(sprintf(decimals,sobelsm),nrow=nrow(sobelsm)))
colnames(sobelsm2)<-sobellab
rownames(sobelsm2)<-direffl2
if (outscreen==1)
{cat("\n Normal theory test for relative indirect effects:\n")
print(sobelsm2,right=T)}
}
}
}
if ((effsize==1) & (boot > 0)){bootres=bootres[2:nrow(bootres),]}
}
if (alttotal==1)
{
altcnms<-"Effect"
totbtvec<-totbtvec+bootdir
alttotfx<-t(totbtvec[1,])
if (boot > 0)
{
alttotfx<-matrix(0,ncol(totbtvec),4)
alttotfx[,1]<-t(totbtvec[1,])
for (cec in (1:ncol(totbtvec)))
{
if (bc==0){bcitmp<-process.pboot3(totbtvec[2:nrow(totbtvec),cec],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(totbtvec[2:nrow(totbtvec),cec],totbtvec[1,cec],xp2,badend,priorlo,priorhi)
bcitmp<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
alttotfx[cec,2:4]<-t(bcitmp)
}
altcnms<-c(altcnms,"BootSE","BootLLCI","BootULCI")
}
resultm2<-matrix(99999,nrow(alttotfx),maxresm)
resultm2[1:nrow(alttotfx),1:ncol(alttotfx)]<-alttotfx
resultm<-rbind(resultm,resultm2)
if (outscreen==1)
{
if (nxvls > 1)
{cat("----------\n")
cat("\nRelative total effects of X on Y (sum of direct and indirect effects):\n")
alttotfp<-noquote(matrix(sprintf(decimals,alttotfx),nrow=nrow(alttotfx)))
colnames(alttotfp)<-altcnms
rownames(alttotfp)<-direffl2
print(alttotfp,right=T)
}
if (nxvls==1)
{
cat("\nTotal effects of X on Y (sum of direct and indirect effects):\n")
alttotfp<-noquote(matrix(sprintf(decimals,alttotfx),nrow=nrow(alttotfx)))
colnames(alttotfp)<-altcnms
rownames(alttotfp)<-" "
print(alttotfp,right=T)
}
}
}
}
#this is the end of the no moderators loop */
if (anymod > 0)
{
if (boot==0){bootres<-obscoeff;indtab<-999}
if (boot > 0){bootres<-rbind(obscoeff,bootres);indtab<-matrix(999,1,4)}
if (sum(as.numeric(indmod > 0))==nrow(indmod))
{if (outscreen==1)
{
if (nxvls > 1)
{
if (xmint==0)
{cat("\nRelative conditional indirect effects of X on Y:\n")}
if (xmint==1)
{cat("\nRelative (total) natural indirect effects of X on Y:\n\n")}
}
if (nxvls==1)
{
if (xmint==0)
{cat("\nConditional indirect effects of X on Y:\n")}
if (xmint==1)
{cat("\n (Total) Natural indirect effect(s) of X on Y:\n\n")}
}
}
}
if (sum(as.numeric(indmod > 0)) < nrow(indmod))
{if (outscreen==1)
{
if (nxvls > 1)
{cat("\nRelative conditional and unconditional indirect effects of X on Y:\n")}
if (nxvls==1)
{cat("\nConditional and unconditional indirect effects of X on Y:\n")}
}
}
cftotfx=matrix(0,nrow(bootres),nxvls)
for (i in (1:nrow(indmake)))
{
indtab<-matrix(0,1,4)
indkeyt<-indkey[i,]
if (outscreen==1)
{
if (xmint==0)
{cat("\nINDIRECT EFFECT:\n\n")}
write.table(t(indkeyt),quote=FALSE,row.names=FALSE,col.names=FALSE,sep=" ")
cat("\n")
}
if (indmod[i,1]==0)
{
for (j in (1:nxvls))
{
indtemp<-matrix(1,nrow(bootres),1)
for (k in (1:indmake[i,1]))
{
jtemp<-1
if ((j > 1) & (k==1)){jtemp<-j}
indtemp<-indtemp*bootres[,pathsfoc[jtemp,indmake[i,(k+1)]]]
}
indeff<-indtemp[1,1]
if (boot > 0)
{
if (bc==0){bcitmp3<-process.pboot3(indtemp[2:nrow(indtemp),1],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(indtemp[2:nrow(indtemp),1],indtemp[1,1],xp2,badend,priorlo,priorhi)
bcitmp3<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indeff<-cbind(indeff,t(bcitmp3))
}
indtab<-rbind(indtab,indeff)
}
indtab<-matrix(indtab[2:nrow(indtab),],ncol=ncol(indtab))
resultm2<-matrix(99999,nrow(indtab),maxresm)
resultm2[1:nrow(indtab),1:ncol(indtab)]<-indtab
resultm<-rbind(resultm,resultm2)
indtab10<-noquote(matrix(sprintf(decimals,indtab),nrow=nrow(indtab)))
if (nxvls > 1)
{rownames(indtab10)<-xcatlab[1:nxvls,1]}
if (nxvls==1)
{rownames(indtab10)<-" "}
colnames(indtab10)<-c("Effect","BootSE","BootLLCI","BootULCI")
if (outscreen==1)
{print(indtab10,right=T)}
}
# end of unmoderated
# start of moderated
if (indmod[i,1] > 0)
{
if (indmod[i,1]==1)
{indmodva<-wmodvals;indprova<-wprobval;condlbs<-wnames;printw<-1}
if (indmod[i,1]==2)
{indmodva<-zmodvals;indprova<-zprobval;condlbs<-znames;printz<-1}
if (indmod[i,1]==3)
{
cntmp<-1;printz<-1;printw<-1
indmodva<-matrix(999,(nrow(wmodvals)*nrow(zmodvals)),2)
for (k7 in (1:nrow(wmodvals)))
{
for (k8 in (1:nrow(zmodvals)))
{indmodva[cntmp,]<-cbind(wmodvals[k7,1],zmodvals[k8,1]);cntmp<-cntmp+1}
}
condlbs<-cbind(wnames,znames)
}
condres<-matrix(999,nrow(indmodva),1)
if (boot > 0)
{condres=matrix(999,nrow(indmodva),4)}
condres<-cbind(indmodva,condres)
# Here is where the computations start
for (k4 in (1:nxvls))
{
imm3<-matrix(1,nrow(bootres),1);imm4<-matrix(1,nrow(bootres),1);indcontr<-0
if (indmod[i,1]==3){tihsw<-wprobval;tihsz<-zprobval}
for (k1 in (1:nrow(indmodva)))
{
tucker2<-matrix(1,nrow(bootres),1)
imm2<-matrix(1,nrow(bootres),1)
wfirst<-0;zfirst<-0;immset<-0
for (k2 in (1:indmake[i,1]))
{
colnumb<-indmake[i,(k2+1)]
if (k2==1)
{
wbb<-matrix(0,nrow(bootres),(nwvls*nxvls))
zbb<-matrix(0,nrow(bootres),(nzvls*nxvls))
wzbb<-matrix(0,nrow(bootres),(nwvls*nzvls*nxvls))
}
if (k2 != 1)
{
wbb<-matrix(0,nrow(bootres),nwvls)
zbb<-matrix(0,nrow(bootres),nzvls)
wzbb<-matrix(0,nrow(bootres),(nwvls*nzvls))
}
cnt<-1;tihs<-matrix(indlocs[2:((indlocs[1,colnumb])+1),colnumb])
if (k2==1)
{
focbb<-matrix(tihs[1:nxvls,1]);focbb<-matrix(bootres[,focbb],ncol=nxvls)
if (indmmm[i,1] > 0)
{imm<-matrix(focbb[,k4]);condbb<-matrix(imm,ncol=ncol(imm))}
focaddon<-matrix(0,1,nxvls);focaddon[1,k4]<-1;cnt<-cnt+nxvls;placeh<-nxvls
if (indmod[i,1]==1)
{
tihsz<-matrix(0,nrow(wprobval),(nzvls*nxvls))
tihswz<-matrix(0,nrow(wprobval),(nwvls*nzvls*nxvls))
if (pathsw[1,colnumb]==1)
{
temp<-matrix(0,nrow(wprobval),(nxvls*nwvls))
for (k5 in (1:nrow(wprobval)))
{
for (k6 in (1:nwvls))
{temp[k5, (((k4-1)*nwvls)+k6)]<-wprobval[k5,k6]}
}
indprova<-cbind(temp,tihsz,tihswz)
} else {
indprova<-cbind(wprobval,tihsz,tihswz)}
}
if (indmod[i,1]==2)
{
tihsw<-matrix(0,nrow(zprobval),(nwvls*nxvls))
tihswz<-matrix(0,nrow(zprobval),(nwvls*nzvls*nxvls))
if (pathsz[1,colnumb]==1)
{
temp<-matrix(0,nrow(zprobval),(nxvls*nzvls))
for (k5 in (1:nrow(zprobval)))
{
for (k6 in (1:nzvls))
{temp[k5,(((k4-1)*nzvls)+k6)]<-zprobval[k5,k6]}
}
indprova<-cbind(tihsw,temp,tihswz)
} else {
indprova<-cbind(tihsw,zprobval,tihswz)}
}
if (indmod[i,1]==3)
{
indprova<-matrix(0,(nrow(wprobval)*nrow(zprobval)),((ncol(wprobval)*nxvls)+(ncol(zprobval)*nxvls)+(nwvls*nzvls*nxvls)))
cntemp<-1
for (k7 in (1:nrow(wprobval)))
{
for (k8 in (1:nrow(zprobval)))
{
temp<-(wprobval[k7,]*focaddon[1,k4])
indprova[cntemp,(((k4-1)*nwvls)+1):(k4*(nwvls))]<-temp
temp<-zprobval[k8,]*focaddon[1,k4]
indprova[cntemp,((((k4-1)*nzvls)+1)+(nxvls*nwvls)):((((k4-1)*nzvls)+1)+(nxvls*nwvls)+(nzvls-1))]<-temp
cntemp<-cntemp+1
}
}
if (pathsz[1,colnumb]==0)
{
temp<-matrix(0,nrow(indprova),(ncol(zprobval)*nxvls))
indprova[,((ncol(wprobval)*nxvls)+1):((ncol(wprobval)+ncol(zprobval))*nxvls)]<-temp
}
if (pathsw[1,colnumb]==0)
{
temp<-matrix(0,nrow(indprova),(ncol(wprobval)*nxvls))
indprova[,1:(ncol(wprobval)*nxvls)]<-temp
}
if (pathswz[1,colnumb]==1)
{
cntemp<-(ncol(wprobval)*nxvls)+(ncol(zprobval)*nxvls)+((k4-1)*ncol(wprobval)*ncol(zprobval))+1
for (k7 in (1:ncol(wprobval)))
{
for (k8 in (1:ncol(zprobval)))
{
indprova[,cntemp]<-matrix(indprova[,((ncol(wprobval)*(k4-1))+k7)])*matrix(indprova[,((((k4-1)*ncol(zprobval))+k8)+(nxvls*ncol(wprobval)))])
cntemp<-cntemp+1
}
}
}
}
}
if (k2 > 1)
{
focbb<-tihs[1,1];focbb=matrix(bootres[,focbb])
if (indmmm[i,1] > 0){imm<-matrix(focbb[,1]);condbb<-matrix(imm)}
focaddon<-matrix(1);cnt<-cnt+1;placeh<-1
if (indmod[i,1]==1)
{
tihsz<-matrix(0,nrow(wprobval),nzvls)
tihswz<-matrix(0,nrow(wprobval),(nwvls*nzvls))
indprova<-cbind(wprobval,tihsz,tihswz)
}
if (indmod[i,1]==2)
{
tihsw<-matrix(0,nrow(zprobval),nwvls)
tihswz<-matrix(0,nrow(zprobval),(nwvls*nzvls))
indprova<-cbind(tihsw,zprobval,tihswz)
}
if (indmod[i,1]==3)
{
indprova<-matrix(0,(nrow(wprobval)*nrow(zprobval)),((ncol(wprobval)+ncol(zprobval))+(nwvls*nzvls)))
cntemp<-1
for (k7 in (1:nrow(wprobval)))
{
for (k8 in (1:nrow(zprobval)))
{
indprova[cntemp,1:(ncol(wprobval)+ncol(zprobval))]<-cbind(t(matrix(wprobval[k7,])),t(matrix(zprobval[k8,])))
cntemp<-cntemp+1
}
}
if (pathsz[1,colnumb]==0)
{
temp<-matrix(0,nrow(indprova),ncol(zprobval))
indprova[,(ncol(wprobval)+1):(ncol(wprobval)+ncol(zprobval))]<-temp
}
if (pathsw[1,colnumb]==0)
{
temp<-matrix(0,nrow(indprova),ncol(wprobval))
indprova[,1:ncol(wprobval)]<-temp
}
if (pathswz[1,colnumb]==1)
{
cntemp<-(ncol(wprobval)+ncol(zprobval)+1)
for (k7 in (1:ncol(wprobval)))
{
for (k8 in (1:ncol(zprobval)))
{
indprova[,cntemp]<-matrix(indprova[,k7])*matrix(indprova[,(ncol(wprobval)+k8)])
cntemp<-cntemp+1
}
}
}
}
}
if (pathsw[1,colnumb]==1)
{
wbb<-matrix(tihs[cnt:(cnt+(placeh*nwvls)-1),1])
wbb<-matrix(bootres[,wbb],ncol=nrow(wbb))
immlbs2<-matrix(wcatlab[1:nwvls,1])
if (zfirst==0){wfirst<-1}
if ((indmmm[i,1]==1) | (indmmm[i,1]==31) | (indmmm[i,1]==51))
{
imm<-matrix(wbb[,1])
for (k7 in (1:nwvls))
{imm<-cbind(imm,wbb[,(((k4-1)*nwvls*(as.numeric(k2==1)))+k7)])}
imm<-matrix(imm[,2:ncol(imm)],ncol=(ncol(imm)-1))
}
if ((indmmm[i,1]==41) | (indmmm[i,1]==51))
{
condbb<-matrix(0,nrow(bootres),1)
for (k7 in (1:nwvls))
{condbb<-cbind(condbb,wbb[,(((k4-1)*nwvls*(as.numeric(k2==1)))+k7)])}
condbb<-matrix(condbb[,2:ncol(condbb)],ncol=(ncol(condbb)-1))
}
cnt<-cnt+(placeh*nwvls)
}
if (pathsz[1,colnumb]==1)
{
zbb<-matrix(tihs[cnt:(cnt+(placeh*nzvls)-1),1])
zbb<-matrix(bootres[,zbb],ncol=nrow(zbb))
if (wfirst==0){zfirst<-1}
if (indmmm[i,1] != 31){immlbs2<-matrix(zcatlab[1:nzvls,1])}
if ((indmmm[i,1]==2) | (indmmm[i,1]==31) | (indmmm[i,1]==51))
{
if (indmmm[i,1]==2){imm<-matrix(zbb[,1])}
for (k7 in (1:nzvls))
{imm<-cbind(imm,zbb[,(((k4-1)*nzvls*(as.numeric(k2==1)))+k7)])}
if ((indmmm[i,1]==2) | (indmmm[i,1]==51))
{
imm<-matrix(imm[,2:ncol(imm)],ncol=(ncol(imm)-1))
if (indmmm[i,1]==51){condbb<-cbind(condbb,imm)}
}
}
cnt<-cnt+(placeh*nzvls)
}
if (pathswz[1,colnumb]==1)
{
wzbb<-matrix(tihs[cnt:(cnt+(placeh*nwvls*nzvls)-1),1])
wzbb<-matrix(bootres[,wzbb],ncol=nrow(wzbb))
if (indmmm[i,1]==41)
{
imm<-matrix(wzbb[,1])
for (k7 in (1:(nwvls*nzvls)))
{imm<-cbind(imm,wzbb[,(((k4-1)*nzvls*nwvls*(as.numeric(k2==1)))+k7)])}
}
if (indmmm[i,1]==41)
{
imm<-matrix(imm[,2:ncol(imm)],ncol=(ncol(imm)-1))
condbb<-cbind(condbb,imm[,(ncol(imm)-(nwvls*nzvls)+1):ncol(imm)])
}
cnt<-cnt+(placeh*nzvls*nwvls)
}
indprobe<-cbind(focaddon,t(matrix(indprova[k1,])))
tucker<-cbind(focbb,wbb,zbb,wzbb)
for (k3 in (1:ncol(indprobe)))
{tucker[,k3]<-matrix(tucker[,k3]*indprobe[1,k3])}
tucker2<-tucker2*matrix(rowSums(tucker))
if ((indmmm[i,1]==1) | (indmmm[i,1]==2) | (indmmm[i,1]==31) | (indmmm[i,1]==41) | (indmmm[i,1]==51))
{
if (immset==1)
{
if ((ncol(imm2)==1) & (ncol(imm)==1)){imm2<-(matrix(imm2)*matrix(imm))}
if ((indmmm[i,1]==41) | (indmmm[i,1]==51))
{
if ((ncol(condbb2) > 1) & (ncol(condbb) > 1))
{
condbb2t<-matrix(-999999,nrow(condbb2),(ncol(condbb2)*ncol(condbb)))
k9<-1
if (wfirst==1)
{
for (k7 in (1:ncol(condbb2)))
{
for (k8 in (1:ncol(condbb)))
{condbb2t[,k9]<-(matrix(condbb2[,k7])*matrix(condbb[,k8]));k9<-k9+1}
}
}
if (zfirst==1)
{
for (k7 in (1:ncol(condbb)))
{
for (k8 in (1:ncol(condbb2)))
{condbb2t[,k9]<-(matrix(condbb[,k7])*matrix(condbb2[,k8]));k9<-k9+1}
}
}
condbb2<-matrix(condbb2t,ncol=ncol(condbb2t))
}
if ((ncol(condbb2) > 1) & (ncol(condbb)==1))
{
for (k7 in (1:ncol(condbb2)))
{condbb2[,k7]<-(matrix(condbb2[,k7])*matrix(condbb))}
}
if ((ncol(condbb2)==1) & (ncol(condbb) > 1))
{
for (k7 in (1:ncol(condbb)))
{condbb[,k7]<-(matrix(condbb2)*matrix(condbb[,k7]))}
condbb2<-matrix(condbb,ncol=ncol(condbb))
}
}
if ((ncol(imm2) != 1) & (ncol(imm) != 1))
{
imm2t<-matrix(-999999,nrow(imm2),(ncol(imm2)*ncol(imm)))
k9<-1
if (wfirst==1)
{
for (k7 in (1:ncol(imm2)))
{
for (k8 in (1:ncol(imm)))
{imm2t[,k9]<-(matrix(imm2[,k7])*matrix(imm[,k8]));k9<-k9+1}
}
}
if (zfirst==1)
{
for (k7 in (1:ncol(imm)))
{
for (k8 in (1:ncol(imm2)))
{imm2t[,k9]<-(matrix(imm[,k7])*matrix(imm2[,k8]));k9<-k9+1}
}
}
imm2<-matrix(imm2t,ncol=ncol(imm2t))
}
if ((ncol(imm2) > 1) & (ncol(imm)==1))
{
for (k7 in (1:ncol(imm2)))
{imm2[,k7]<-(matrix(imm2[,k7])*matrix(imm))}
}
if ((ncol(imm2)==1) & (ncol(imm) > 1))
{
for (k7 in (1:ncol(imm)))
{imm[,k7]<-(matrix(imm2)*matrix(imm[,k7]))}
imm2<-matrix(imm,ncol=ncol(imm))
}
}
if (immset==0)
{
imm2<-matrix(imm,ncol=ncol(imm))
if ((indmmm[i,1]==41) | (indmmm[i,1]==51))
{condbb2<-matrix(condbb,ncol=ncol(condbb))}
immset<-1
}
}
# that is it for mmm loop */
}
# end of looping through paths: k2
indtemp<-tucker2[1,1]
if ((indmmm[i,1]==12) | (indmmm[i,1]==22))
{
imm3<-cbind(imm3,tucker2)
if (k1==nrow(indmodva))
{
imm3<-matrix(imm3[,2:ncol(imm3)],ncol=(ncol(imm3)-1))
immstop<-ncol(imm3)
for (k8 in (2:immstop))
{
if (indmmmt[i,1]==1){imm3<-cbind(imm3,(imm3[,k8]-imm3[,1]))}
if (indmmmt[i,1]==2){imm3=cbind(imm3,(imm3[,k8]-imm3[,(k8-1)]))}
if (indmmmt[i,1]==3)
{
imm3<-cbind(imm3,((rowSums(imm3[,(k8:immstop)])/(immstop-k8+1))-imm3[,(k8-1)]))
}
if (indmmmt[i,1]==4)
{imm3<-cbind(imm3,(imm3[,k8]-(rowSums(imm3[,1:immstop])/immstop)))}
}
if (indmmmt[i,1] < 5)
{imm2<-matrix(imm3[,(immstop+1):ncol(imm3)],ncol=(ncol(imm3)-immstop))}
}
}
if ((indmmm[i,1]>-1) & ((contrast==1) | (contrast==2)))
{
imm4<-cbind(imm4,tucker2)
if ((k1==nrow(indmodva)) & (k1 > 1))
{
imm4<-matrix(imm4[,2:ncol(imm4)],ncol=(ncol(imm4)-1))
immstop<-ncol(imm4)
condcont<-matrix(-999,(immstop*(immstop-1)/2),6)
for (k8 in (1:(immstop-1)))
{
for (k9 in ((k8+1):immstop))
{
if (contrast==1){imm4<-cbind(imm4,matrix(imm4[,k9]-imm4[,k8]))}
if (contrast==2){imm4<-cbind(imm4,matrix(abs(imm4[,k9])-abs(imm4[,k8])))}
condcont[(ncol(imm4)-immstop),1]<-imm4[1,k9]
condcont[(ncol(imm4)-immstop),2]<-imm4[1,k8]
}
}
imm4<-matrix(imm4[,(immstop+1):ncol(imm4)],ncol=(ncol(imm4)-immstop))
for (k8 in (1:ncol(imm4)))
{
condcont[k8,3]<-imm4[1,k8]
if (boot > 0)
{
if (bc==0){condcon3<-process.pboot3(imm4[2:nrow(imm4),k8],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(imm4[2:nrow(imm4),k8],imm4[1,k8],xp2,badend,priorlo,priorhi)
condcon3<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
condcont[k8,4:6]<-t(condcon3)
}
}
if (boot==0){condcont<-matrix(condcont[,1:3],ncol=3)}
indcontr<-1
}
}
if (xmint==1)
{
if (k1==(k4+1))
{cftotfx[,k4]<-cftotfx[,k4]+(tucker2*xscaling)}
}
if (boot > 0)
{
tucker2<-tucker2*xscaling
if (bc==0){bcitmp11<-process.pboot3(tucker2[2:nrow(tucker2),1],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(tucker2[2:nrow(tucker2),1],tucker2[1,1],xp2,badend,priorlo,priorhi)
bcitmp11<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
indtemp<-cbind((indtemp*xscaling),t(bcitmp11))
}
if (boot==0)
{indtemp<-indtemp*xscaling}
condres[k1,(ncol(indmodva)+1):ncol(condres)]<-indtemp
}
# end of looping through indirect effects: k1
# Here is where the computations end
if (xmint==0)
{
resultm2<-matrix(99999,nrow(condres),maxresm)
resultm2[1:nrow(condres),1:ncol(condres)]<-condres
resultm<-rbind(resultm,resultm2)
}
condresp<-noquote(matrix(sprintf(decimals,condres),nrow=nrow(condres)))
if (xmint==1)
{
if (k4==1)
{
natindfx<-matrix(condres[(2+(k4-1)),2:ncol(condres)],nrow=1)
}
if (k4 > 1)
{
natindfx<-rbind(natindfx,condres[(2+(k4-1)),2:ncol(condres)])
}
if (k4==nxvls)
{
resultm2<-matrix(99999,nrow(natindfx),maxresm)
resultm2[1:nrow(natindfx),1:ncol(natindfx)]<-natindfx
resultm<-rbind(resultm,resultm2)
}
}
if (k4==1)
{
condlbs<-cbind(condlbs,"Effect")
if (boot > 0)
{condlbs<-cbind(condlbs,"BootSE","BootLLCI","BootULCI")}
condrlb<-t(matrix(replicate(nrow(condres)," ")))
}
if (nxvls > 1)
{condrlb<-matrix(xcatlab[k4,1],nrow(condres),1)}
colnames(condresp)<-condlbs
rownames(condresp)<-condrlb
if ((outscreen==1) & (xmint==0))
{print(condresp,right=T)}
if ((outscreen==1) & (xmint==1) & (k4==nxvls))
{
natindf2<-noquote(matrix(sprintf(decimals,natindfx),nrow=nrow(natindfx)))
colnames(natindf2)<-condlbs[,2:ncol(condlbs)]
if (nxvls > 1)
{rownames(natindf2)<-direffl2}
if (nxvls==1)
{rownames(natindf2)<-" "}
print(natindf2,right=T)
#here
cat("\n")
}
if (indmmm[i,1]==0){cat("\n")}
dichadj<-0;immcat<-0
if ((indmmm[i,1] > 0) & (xmint==0))
{
if ((indmmm[i,1]==1) | (indmmm[i,1]==12) | (indmmm[i,1]==31))
{
if ((wdich==1) & (mcw==0))
{
if (indmmm[i,1] != 12){imm2[,1]<-imm2[,1]*(wmax-wmin)}
if (indmmm[i,1] != 31){dichadj<-1}
}
if (((mcw==1) | (mcw==2)) & (indmmm[i,1] != 31)){immcat<-1}
}
if ((indmmm[i,1]==2) | (indmmm[i,1]==22) | (indmmm[i,1]==31))
{
if ((zdich==1) & (mcz==0))
{
if (indmmm[i,1]==31)
{
imm2[,(nwvls+1):ncol(imm2)]<-matrix(imm2[,(nwvls+1):ncol(imm2)],ncol=(ncol(imm2)-nwvls))*(zmax-zmin)
}
if (indmmm[i,1]==2){imm2[,1]<-imm2[,1]*(zmax-zmin)}
if (indmmm[i,1] != 31){dichadj<-1}
}
if (((mcz==1) | (mcz==2)) & (indmmm[i,1] != 31)){immcat<-1}
}
immtemp2<-t(matrix(imm2[1,],ncol=ncol(imm2)))
immtemp<-matrix(immtemp2,ncol=ncol(immtemp2))
immlbs<-"Index"
if (boot > 0)
{
immtemp<-matrix(0,1,3)
for (k7 in (1:ncol(imm2)))
{
if (bc==0){immbtci<-process.pboot3(imm2[2:nrow(imm2),k7],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(imm2[2:nrow(imm2),k7],imm2[1,k7],xp2,badend,priorlo,priorhi)
immbtci<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
immtemp<-rbind(immtemp,t(immbtci))
}
immtemp<-matrix(immtemp[2:nrow(immtemp),],ncol=ncol(immtemp))
immtemp<-cbind(immtemp2,immtemp)
immlbs<-c(immlbs,"BootSE","BootLLCI","BootULCI")
}
resultm2<-matrix(99999,nrow(immtemp),maxresm)
resultm2[1:nrow(immtemp),1:ncol(immtemp)]<-immtemp
resultm<-rbind(resultm,resultm2)
immtempr<-noquote(matrix(sprintf(decimals,immtemp),nrow=nrow(immtemp)))
colnames(immtempr)<-immlbs
if ((dichadj==0) & (immcat==0) & (indmmmt[i,1] != 5) & (indmmm[i,1] < 100))
{
if (indmmm[i,1] < 30)
{
rownames(immtempr)<-immlbs2
if (outscreen==1)
{cat("\n Index of moderated mediation:\n")
print(immtempr,right=T)}
if ((nxvls > 1) & (k4 < nxvls)){cat("\n")}
}
if (indmmm[i,1]==31)
{
immlbs2<-rbind(immlbs2,matrix(zcatlab[1:nzvls,1]))
rownames(immtempr)<-immlbs2
if (outscreen==1)
{cat("\n Indices of partial moderated mediation:\n")
print(immtempr,right=T)}
if ((nxvls > 1) & (k4 < nxvls)){cat("\n")}
}
if ((nzvls==1) & (nwvls==1))
{
if ((indmmm[i,1]==41) | (indmmm[i,1]==51))
{
for (k7 in (1:nwvls))
{
immlbs2<-zcatlab[1:nzvls,1]
immtemp2<-matrix(immtemp[(((k7-1)*nzvls)+1):(((k7-1)*nzvls)+nzvls),],ncol=ncol(immtemp))
#resultm2<-matrix(99999,nrow(immtemp2),maxresm)
#resultm2[1:nrow(immtemp2),1:ncol(immtemp2)]<-immtemp2
#print(resultm)
#print(resultm2)
#resultm<-rbind(resultm,resultm2)
#print(resultm)
immtem2r<-noquote(matrix(sprintf(decimals,immtemp2),nrow=nrow(immtemp2)))
colnames(immtem2r)<-immlbs
if (nwvls > 1)
{
primodv<-cbind("Primary moderator:", wcatlab[k7,1])
if (outscreen==1)
{write.table(primodv,quote=FALSE,row.names=FALSE,col.names=FALSE)}
}
if (nzvls==1)
{
rownames(immtem2r)<-" "
if (outscreen==1)
{cat("\n Index of moderated moderated mediation:\n")
print(immtem2r,right=T)}
} else {
rownames(immtem2r)<-immlbs2
if (outscreen==1)
{cat("\n Indices of moderated moderated mediation:\n")
print(immtem2r,right=T)}
}
cmmtemp<-matrix(0,nrow(zprobval),4)
for (k8 in (1:nrow(zprobval)))
{
bbst<-((nwvls+1)+((k7-1)*nzvls));bben<-((nwvls+1)+((k7-1)*nzvls)+(nzvls-1))
condbb3<-matrix(condbb2[,bbst:bben],ncol=(bben-bbst+1))
if (ncol(zprobval) > 1)
{
condbb3<-condbb3*diag(c(zprobval[k8,]))
} else {
condbb3<-condbb3*zprobval[k8,]
}
condbb3<-cbind(condbb2[,k7],condbb3)
icmm<-matrix(rowSums(condbb3))
cmmtemp[k8,1]<-icmm[1,1]
if (boot > 0)
{
if (bc==0){cmmt3<-process.pboot3(icmm[2:nrow(icmm),1],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(icmm[2:nrow(icmm),1],icmm[1,1],xp2,badend,priorlo,priorhi)
cmmt3<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
cmmtemp[k8,2:4]<-t(cmmt3)
}
cmmlbs<-cbind(znames,t(matrix(immlbs)))
}
if (boot==0){cmmtemp<-matrix(cmmtemp[,1:1],ncol=1);cmmlbs<-cbind(znames,"Index")}
cmmtemp<-cbind(zmodvals,cmmtemp)
resultm2<-matrix(99999,nrow(cmmtemp),maxresm)
resultm2[1:nrow(cmmtemp),1:ncol(cmmtemp)]<-cmmtemp
resultm<-rbind(resultm,resultm2)
cmmtempr<-noquote(matrix(sprintf(decimals,cmmtemp),nrow=nrow(cmmtemp)))
#if (boot==0){cmmtempr<-matrix(cmmtemp[,1:2],ncol=2)}
#cmmlbs<-cbind(znames,t(matrix(immlbs)))
rownames(cmmtempr)<-t(matrix(replicate(nrow(cmmtempr)," ")))
colnames(cmmtempr)<-cmmlbs
if (outscreen==1)
{cat("\n Indices of conditional moderated mediation by W:\n")
print(cmmtempr,right=T)}
}
}
}
}
if (((dichadj==1) | (immcat==1)) & (indmmm[i,1] < 30))
{
if (outscreen==1)
{
cat("\n Index of moderated mediation\n")
cat(" (differences beween conditional indirect effects):\n")
rownames(immtempr)<-immlbs2
print(immtempr,right=T)
}
}
}
if (indcontr==1)
{
resultm2<-matrix(99999,nrow(condcont),maxresm)
resultm2[1:nrow(condcont),1:ncol(condcont)]<-condcont
resultm<-rbind(resultm,resultm2)
condcnt3<-noquote(matrix(sprintf(decimals,condcont),nrow=nrow(condcont)))
condctlb<-c("Effect1","Effect2","Contrast","BootSE", "BootLLCI","BootULCI")
colnames(condcnt3)<-condctlb
rownames(condcnt3)<-t(matrix(replicate(nrow(condcnt3)," ")))
if (outscreen==1)
{
cat("\n Pairwise contrasts between conditional indirect effects\n")
cat(" (Effect1 minus Effect2):\n")
print(condcnt3,right=T)
}
}
#if (outscreen==1)
#{cat("\n---\n")}
}
}
#end of moderated */
}
if (alttotal==1)
{
if (outscreen==1){cat("\n----------\n")}
altcnms<-"Effect"
alttotfx<-matrix(cftotfx[1,])+obnatdfx
if (boot > 0)
{
alttotfx<-matrix(0,ncol(cftotfx),4)
alttotfx[,1]<-matrix(cftotfx[1,])+obnatdfx
natdirbt[1,]<-t(obnatdfx)
cftotfx<-cftotfx+natdirbt
for (cec in (1:ncol(cftotfx)))
{
if (bc==0){cftot34<-process.pboot3(cftotfx[2:nrow(cftotfx),cec],cilow,cihigh)}
if (bc==1)
{
bcbout<-process.bcboot3(cftotfx[2:nrow(cftotfx),cec],cftotfx[1,cec],xp2,badend,priorlo,priorhi)
cftot34<-matrix(unlist(bcbout[1]))
badend<-unlist(bcbout[2]);priorlo<-unlist(bcbout[3]);priorhi<-unlist(bcbout[4])
}
alttotfx[cec,2:4]<-t(cftot34)
}
altcnms<-c(altcnms,"BootSE", "BootLLCI","BootULCI")
}
resultm2<-matrix(99999,nrow(alttotfx),maxresm)
resultm2[1:nrow(alttotfx),1:ncol(alttotfx)]<-alttotfx
resultm<-rbind(resultm,resultm2)
alttofx2<-noquote(matrix(sprintf(decimals,alttotfx),nrow=nrow(alttotfx)))
if (outscreen==1)
{
if (nxvls > 1)
{
cat("\nRelative total effects of X on Y (sum of direct and indirect effects:\n")
rownames(alttofx2)<-direffl2
}
if (nxvls==1)
{
cat("\nTotal effect of X on Y (sum of direct and indirect effects:\n")
rownames(alttofx2)<-" "
}
colnames(alttofx2)<-altcnms
print(alttofx2,right=T)
}
}
}
# This is the end of the moderated loop */
}
if ((criterr==0) & (saveboot==1))
{
if (boot > 0)
{
if (outscreen==1)
{
cat("\n*********************************************************************** \n")
conseq<-conseq[2:nrow(conseq),]
#cat("Bootstrap estimates were saved in a global dataframe named process.boots\n")
colslab<-cbind(savlabs,conseq,vlabs)
cat("\nMap of column names to model coefficients in bootstrap matrix:\n")
rownames(colslab)<-t(matrix(replicate(nrow(colslab)," ")))
colnames(colslab)<-c("name","Conseqnt","Antecdnt")
print(noquote(colslab),right=T)
}
}
}
#PRINT BOOTSTRAP RESULTS FOR MODEL PARAMETERS
if ((criterr==0) & (boot > 0) & (modelbt==1))
{
labstart<-1
if (outscreen==1)
{cat("\n********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********\n\n")}
for (iboot in (1:(nms+nys)))
{
vlabsm<-matrix(vlabs[labstart:(labstart+(nump[1,iboot]-1)),1])
bootcimt<-matrix(bootcim[labstart:(labstart+(nump[1,iboot]-1)),],ncol=5)
resultm2<-matrix(99999,nrow(bootcimt),maxresm)
resultm2[1:nrow(bootcimt),1:ncol(bootcimt)]<-bootcimt
resultm<-rbind(resultm,resultm2)
bootcimt<-noquote(matrix(sprintf(decimals,bootcimt),ncol=5))
colnames(bootcimt)<-matrix(c("Coeff","BootMean","BootSE","BootLLCI","BootULCI"))
rownames(bootcimt)<-vlabsm
if (outscreen==1)
{
cat("Outcome variable: ")
write.table(outnames[iboot,1],quote=FALSE,row.names=FALSE,col.names=FALSE)
cat("\n")
print(bootcimt,right=T)
}
labstart<-labstart+nump[1,iboot]
if ((iboot < (nms+nys)) & (outscreen==1)){cat("----------\n")}
}
}
#print model matrices
if ((criterr==0) & (matrices==1) & (outscreen==1))
{
cat("\n********************* MODEL DEFINITION MATRICES *********************** \n \n")
cat("FROM variables are columns, TO variables are rows. \n \n")
temp2<-matrix("0",nrow(bcmat),ncol(bcmat))
for (i in c(2:nrow(bcmat)))
{for (j in c(1:(ncol(bcmat)-1)))
{if (bcmat[i,j]==1){temp2[i,j]<-"1"}
if (j >= i){temp2[i,j]<-" "}}
}
temp2<-as.matrix(noquote(temp2[2:nrow(bcmat),(1:(ncol(bcmat)-1))]))
if (nms > 0){cmatlabs<-c(xnames,mnames);rmatlabs<-c(mnames,ynames)}
if (nms==0){cmatlabs<-xnames;rmatlabs<-ynames}
colnames(temp2)<-cmatlabs
rownames(temp2)<-rmatlabs
cat("BMATRIX: Paths freely estimated (1) and fixed to zero (0): \n")
print(temp2)
z<-0
if (sum(wcmat) !=0)
{
temp2<-matrix("0",nrow(wcmat),ncol(wcmat))
for (i in c(2:nrow(wcmat)))
{for (j in c(1:(ncol(wcmat)-1)))
{if (wcmat[i,j]==1){temp2[i,j]<-"1"}
if (j >= i){temp2[i,j]<-" "}}
}
temp2<-as.matrix(noquote(temp2[2:nrow(wcmat),(1:(ncol(wcmat)-1))]))
colnames(temp2)<-cmatlabs
rownames(temp2)<-rmatlabs
cat("\nWMATRIX: Paths moderated (1) and not moderated (0) by W: \n")
print(temp2)
}
if (sum(zcmat) !=0)
{
temp2<-matrix("0",nrow(zcmat),ncol(zcmat))
for (i in c(2:nrow(zcmat)))
{for (j in c(1:(ncol(zcmat)-1)))
{if (zcmat[i,j]==1){temp2[i,j]<-"1"}
if (j >= i){temp2[i,j]<-" "}}
}
temp2<-as.matrix(noquote(temp2[2:nrow(zcmat),(1:(ncol(zcmat)-1))]))
colnames(temp2)<-cmatlabs
rownames(temp2)<-rmatlabs
cat("\nZMATRIX: Paths moderated (1) and not moderated (0) by Z: \n")
print(temp2)
}
if (sum(wzcmat) !=0)
{
temp2<-matrix("0",nrow(wzcmat),ncol(wzcmat))
for (i in c(2:nrow(wzcmat)))
{for (j in c(1:(ncol(wzcmat)-1)))
{if (wzcmat[i,j]==1){temp2[i,j]<-"1"}
if (j >= i){temp2[i,j]<-" "}}
}
temp2<-as.matrix(noquote(temp2[2:nrow(wzcmat),(1:(ncol(wzcmat)-1))]))
colnames(temp2)<-cmatlabs
rownames(temp2)<-rmatlabs
cat("\nWZMATRIX: W moderated paths moderated (1) and not moderated (0) by Z: \n")
print(temp2)
}
if (ncs > 0)
{colnames(ccmat)<-covnames
rownames(ccmat)<-rmatlabs
cat("\nCMATRIX: Covariates (columns) in (1) and not in (0) the models of M and Y (rows): \n")
print(ccmat)
}
}
#end print model matrices
if (criterr==0)
{
resultm<-resultm[2:nrow(resultm),]
bocaj<-matrix(as.numeric(resultm==99999),nrow=nrow(resultm))
bocaj<-(colSums(bocaj)==nrow(resultm))
bocaj<-matrix(1-as.numeric(bocaj))
j<-1
for (i in (1:ncol(resultm)))
{if (bocaj[i,1]==1){j<-j+1}}
resultm<-resultm[,1:(j-1)]
resultm[resultm==99999]<-NA
}
if ((outscreen==1) & (activate==0))
{cat("\n******************** ANALYSIS NOTES AND ERRORS ************************ \n")}
if (activate==1)
{cat("*********************************************************************** \n")}
if ((criterr==0) & (outscreen==1))
{
cat("\nLevel of confidence for all confidence intervals in output: ")
write.table(conf,quote=FALSE,row.names=FALSE,col.names=FALSE)
if (boot>0)
{
if ((goodboot==boot) & (bc==0))
{
cat("\nNumber of bootstraps for percentile bootstrap confidence intervals: ")
write.table(boot,quote=FALSE,row.names=FALSE,col.names=FALSE)
}
if ((goodboot==boot) & (bc==1))
{
cat("\nNumber of bootstraps for bias-corrected bootstrap confidence intervals: ")
write.table(boot,quote=FALSE,row.names=FALSE,col.names=FALSE)
}
if (length(badend) > 1)
{
cat("\nWARNING: Bootstrap CI endpoints below are not trustworthy. Decrease confidence\n")
cat("or increase the number of bootstrap samples.\n")
badend<-matrix(badend);badend<-t(badend[2:nrow(badend),1])
badend<-noquote(matrix(sprintf(decimals,badend),nrow=nrow(badend)))
write.table(badend,quote=FALSE,row.names=FALSE,col.names=FALSE)
}
}
if (mc > 0)
{
cat("\nNumber of samples for Monte Carlo confidence intervals: ")
write.table(mc,quote=FALSE,row.names=FALSE,col.names=FALSE)
}
if ((wnotev > 0) & (printw==1))
{
if (wnotev==1)
{cat("\nW values in conditional tables are the 16th, 50th, and 84th percentiles.\n")}
if ((wnotev==2) & (minwwarn==0) & (maxwwarn==0))
{cat("\nW values in conditional tables are the mean and +/- SD from the mean.\n")}
if (minwwarn==1)
{cat("\nW values in conditional tables are the minimum, the mean, and 1 SD above the mean.\n")}
if (maxwwarn==1)
{cat("\nW values in conditional tables are 1 SD below the mean, the mean, and the maximum.\n")}
}
if ((znotev > 0) & (printz==1))
{
if (znotev==1)
{cat("\nZ values in conditional tables are the 16th, 50th, and 84th percentiles.\n")}
if ((znotev==2) & (minzwarn==0) & (maxzwarn==0))
{cat("\nZ values in conditional tables are the mean and +/- SD from the mean.\n")}
if (minzwarn==1)
{cat("\nZ values in conditional tables are the minimum, the mean, and 1 SD above the mean.\n")}
if (maxzwarn==1)
{cat("\nZ values in conditional tables are 1 SD below the mean, the mean, and the maximum.\n")}
}
if (minwwarn > 0)
{cat("\nNOTE: One SD below the mean is below the minimum observed in the data for W,\n")
cat(" so the minimum measurement on W is used for conditioning instead.\n")}
if (maxwwarn > 0)
{cat("\nNOTE: One SD above the mean is above the maximum observed in the data for W,\n")
cat(" so the maximum measurement on W is used for conditioning instead.\n")}
if (minzwarn > 0)
{cat("\nNOTE: One SD below the mean is below the minimum observed in the data for Z,\n")
cat(" so the minimum measurement on Z is used for conditioning instead.\n")}
if (maxzwarn > 0)
{cat("\nNOTE: One SD above the mean is above the maximum observed in the data for Z,\n")
cat(" so the maximum measurement on Z is used for conditioning instead.\n")}
if (pstog==1)
{cat("\nNOTE: Standardized coefficients for dichotomous or multicategorical X are\n")
cat(" in partially standardized form.\n")}
for (i in c(1:100))
{
if (notecode[i,1]==32)
{
cat("\n")
cat("Direct, indirect, and total effects are counterfactually defined \n")
if (xcontcf==0)
{
cat("assuming X by M interaction.\n")
}
if (xcontcf==1)
{
cat("assuming X by M interaction and with the following reference (x_ref) \n")
cat("and counterfactual (x_cf) states for X: \n")
xrefvals=t(xrefvals)
xrefvals<-noquote(matrix(sprintf(decimals,xrefvals),nrow=nrow(xrefvals)))
rownames(xrefvals)<-c("x_ref :","x_cf :")
colnames(xrefvals)<-" "
print(xrefvals,right=T)
}
}
if (notecode[i,1]==1)
{cat(" \n")
cat("NOTE: COVMY is ignored when using CMATRIX option. \n")}
if (notecode[i,1]==2)
{cat(" \n")
cat("NOTE: Confidence level restricted to between 50 and 99.9999%. 95% confidence is provided in output. \n")}
if (notecode[i,1]==3)
{cat(" \n")
cat("NOTE: The following variables were mean centered prior to analysis: \n")
centvar<-c(" ", centvar)
centvar<-t(noquote(centvar))
write.table(centvar,quote=FALSE,row.names=FALSE,col.names=FALSE)
}
if ((notecode[i,1]==4) & (ydich != 1))
{cat(" \n")
cat("NOTE: A heteroscedasticity consistent standard error and covariance matrix estimator was used. \n")}
if (notecode[i,1]==6)
{cat(" \n")
cat("NOTE: Due to estimation problems, some bootstrap samples had to be replaced. \n")
cat(" The number of times this happened was: ")
write.table(badboot,quote=FALSE,row.names=FALSE,col.names=FALSE)}
if (notecode[i,1]==7)
{cat(" \n")
cat("NOTE: The bootstrapping was not completed due to problematic bootstrap samples. \n")
cat(" Bootstrap confidence intervals are therefore suppressed.\n")}
if (notecode[i,1]==8)
{cat(" \n")
cat("NOTE: The number of bootstrap samples was adjusted upward given your desired confidence. \n")}
if (notecode[i,1]==9)
{cat(" \n")
cat("NOTE: WMODVAL is ignored when W is specified as multicategorical. \n")}
if (notecode[i,1]==10)
{cat(" \n")
cat("NOTE: ZMODVAL is ignored when Z is specified as multicategorical. \n")}
if (notecode[i,1]==11)
{cat(" \n")
cat("NOTE: Total effect model generated only when all covariates are specified\n")
cat(" in all models of M and Y.\n")}
if (notecode[i,1]==12)
{cat(" \n")
cat("NOTE: Total effect model generated only when X is freely estimated to\n")
cat(" affect each M and both X and M are freely estimated to affect Y.\n")}
if (notecode[i,1]==30)
{cat(" \n")
cat("NOTE: Your vector of linear hypothesis weights is of the wrong length for this model. \n")}
if (notecode[i,1]==13)
{cat(" \n")
cat("NOTE: There are too many pairwise contrasts to conduct with this model. \n")}
if (notecode[i,1]==14)
{cat(" \n")
cat("NOTE: The number of contrast weights must equal the number of indirect effects. \n")}
if (notecode[i,1]==15)
{cat(" \n")
cat("NOTE: Monte Carlo confidence intervals not available for this model. \n")
cat(" Bootstrapping is used instead.\n")}
if (notecode[i,1]==16)
{cat(" \n")
cat("NOTE: The number of Monte Carlo samples was adjusted upward given your desired confidence. \n")}
if (notecode[i,1]==19)
{cat(" \n")
cat("NOTE: Your contrast matrix is invalid or not applicable to this model. \n")}
if (notecode[i,1]==20)
{cat(" \n")
cat("NOTE: One of the groups specified by your contrast matrix does not exist in the data. \n")}
if (notecode[i,1]==24)
{cat(" \n")
cat("NOTE: Total effect model not available with dichotomous Y. \n")}
if (notecode[i,1]==25)
{cat(" \n")
cat("NOTE: STAND/EFFSIZE options not available with dichotomous Y. \n")}
if (notecode[i,1]==27)
{cat(" \n")
cat("NOTE: Standardized coefficients not available for models with moderators. \n")}
if (notecode[i,1]==28)
{cat(" \n")
cat("NOTE: The contrast option is not available with a multicategorical X. \n")}
if (notecode[i,1]==31)
{
medmean2<-noquote(matrix(sprintf(decimals,medmeans),nrow=nrow(medmeans)))
rownames(medmean2)<-" "
colnames(medmean2)<-mnames
if (nms > 1)
{
cat(" \n")
cat("NOTE: Controlled direct effect(s) estimated at the following mediator values: \n")
}
if (nms==1)
{
cat(" \n")
cat("NOTE: Controlled direct effect(s) estimated at the following mediator value: \n")
}
print(medmean2,right=T)
}
if (notecode[i,1]==33)
{cat(" \n")
cat("NOTE: Sobel test is not available when using the XMINT option. \n")}
if (notecode[i,1]==34)
{cat(" \n")
cat("NOTE: Standardized effects are not available when using the XMINT option. \n")}
if (notecode[i,1]==36)
{cat(" \n")
cat("NOTE: The XREFVAL option is ignored when X is declared as multicategorical. \n")}
if (notecode[i,1]==37)
{cat(" \n")
cat("NOTE: The CONTRAST option is not available when using the XMINT option. \n")}
if (notecode[i,1]==35)
{cat(" \n")
cat("NOTE: Counterfactual effects estimated at the following covariate values: \n")
coval2<-noquote(matrix(sprintf(decimals,coval),nrow=nrow(coval)))
rownames(coval2)<-" "
colnames(coval2)<-covnames
print(coval2,right=T)}
if ((notecode[i,1]==29) & (listmiss==1))
{cat(" \n")
a<-missrow;conum<-ncol(missrow);allgood<-0;smremain<-12;largesti<-1;smallrow<-0;
if (conum > 12)
{
for (ii in c(1:12))
{
check<-(conum/ii);
if (check==trunc(check))
{
check2<-conum/ii;aok<-ii
if (aok > 2){allgood<-1}
}
if (check != trunc(check))
{
remain<-conum-(ii*trunc(check))
if (remain <= smremain)
{smremain<-remain;largesti<-ii;smallrow<-trunc(conum/largesti)}
}
}
atemp<-a[1,1:(aok*check2)]
atemp<-matrix(atemp,nrow=check2,byrow=TRUE)
cat("NOTE: Missing data resulted in the deletion of the following row(s) of: \n")
cat(" data from the analysis: \n")
if (ncol(atemp) > 2)
{prmatrix(atemp, rowlab=rep(" ",nrow(atemp)),collab=rep(" ",ncol(atemp)))}
if (allgood==0)
{
atemp<-a[1,1:(smallrow*largesti)]
atemp<-matrix(atemp,nrow=smallrow,byrow=TRUE)
btemp<-matrix(a[1,((largesti*smallrow)+1):conum])
prmatrix(atemp,rowlab=rep(" ",nrow(atemp)),collab=rep(" ",ncol(atemp)))
prmatrix(btemp,rowlab=rep(" ",1),collab=rep(" ",ncol(btemp)))
}
}
if (conum <= 12)
{
cat("NOTE: Missing data resulted in the deletion of the following row(s) of \n")
cat(" data from the analysis: \n")
prmatrix(a, rowlab=rep(" ",nrow(a)), collab=rep(" ",ncol(a)))
}
}
}
if ((nmiss > 0) & (listmiss==0))
{cat(" \n")
cat("NOTE: Some cases with missing data were deleted. The number of deleted cases was: ")
write.table(nmiss,quote=FALSE,row.names=FALSE,col.names=FALSE)}
}
# print errors
for (i in c(1:100))
{
if (errcode[i,1]==1)
{cat(" \n")
cat("ERROR: You must specify a Y and an X variable. \n")}
if (errcode[i,1]==2)
{cat(" \n")
cat("ERROR: X, M, or Y variable used more than once or W and Z are the same variable. \n")}
if (errcode[i,1]==3)
{cat(" \n")
cat("ERROR: You have specified more than one variable for W, Y, X, or Z. \n")}
if (errcode[i,1]==4)
{cat(" \n")
cat("ERROR: A variable specified as multicategorical has more than nine categories. \n")}
if (errcode[i,1]==5)
{cat(" \n")
cat("ERROR: One of the categories contains only a single case. \n")}
if (errcode[i,1]==6)
{cat(" \n")
cat("ERROR: Invalid model number in this version of PROCESS. \n")}
if (errcode[i,1]==7)
{cat(" \n")
cat("ERROR: Invalid model number. \n")}
if (errcode[i,1]==8)
{cat(" \n")
cat("ERROR: You must specify an M variable for this model. \n")}
if (errcode[i,1]==9)
{cat(" \n")
cat("ERROR: You have specified an M variable in a model that does not use it. \n")}
if (errcode[i,1]==10)
{cat(" \n")
cat("ERROR: You have specified a W variable in a model that does not use it. \n")}
if (errcode[i,1]==11)
{cat(" \n")
cat("ERROR: You have not specified a W variable in a model that requires it. \n")}
if (errcode[i,1]==12)
{cat(" \n")
cat("ERROR: You have specified a Z variable in a model that does not use it. \n")}
if (errcode[i,1]==13)
{cat(" \n")
cat("ERROR: You have not specified a Z variable in a model that requires it. \n")}
if (errcode[i,1]==15)
{cat(" \n")
cat("ERROR: One of your model variables exhibits no variation (it is a constant). \n")}
if (errcode[i,1]==16)
{cat(" \n")
cat("ERROR: BMATRIX is not the correct length or is otherwise invalid. \n")}
if (errcode[i,1]==17)
{cat(" \n")
cat("ERROR: WMATRIX is not the correct length or is otherwise invalid. \n")}
if (errcode[i,1]==18)
{cat(" \n")
cat("ERROR: ZMATRIX is not the correct length or is otherwise invalid. \n")}
if (errcode[i,1]==19)
{cat(" \n")
cat("ERROR: WZMATRIX is not the correct length or is otherwise invalid. \n")}
if (errcode[i,1]==20)
{cat(" \n")
cat("ERROR: A path fixed at zero cannot be moderated. \n")}
if (errcode[i,1]==60)
{cat(" \n")
cat("PROCESS is now ready for use.\n")
cat("Copyright 2022 by Andrew F. Hayes ALL RIGHTS RESERVED\n")
cat("Workshop schedule at http://haskayne.ucalgary.ca/CCRAM\n \n")}
if (errcode[i,1]==21)
{cat(" \n")
cat("ERROR: If only one moderator is specified, it must be specified as W. \n")}
if (errcode[i,1]==22)
{cat(" \n")
cat("ERROR: In BMATRIX, X must be specified to affect at least one variable. \n")}
if (errcode[i,1]==23)
{cat(" \n")
cat("ERROR: In BMATRIX, at least one variable must be specified to affect Y. \n")}
if (errcode[i,1]==24)
{cat(" \n")
cat("ERROR: You must specify a model number or a custom BMATRIX specification. \n")}
if (errcode[i,1]==25)
{cat(" \n")
cat("ERROR: BMATRIX cannot be used in conjunction with a model number. \n")}
if (errcode[i,1]==26)
{cat(" \n")
cat("ERROR: Your model has a dangling mediator (all Ms must affect and be affected). \n")}
if (errcode[i,1]==29)
{cat(" \n")
cat("ERROR: CMATRIX is not the correct length or is otherwise invalid. \n")}
if (errcode[i,1]==30)
{cat(" \n")
cat("ERROR: In CMATRIX, all covariates must be assigned to an M or a Y. \n")}
if ((errcode[i,1]==31) & (singlr==0))
{cat(" \n")
singlr<-1
cat("ERROR: A linear or near linear dependence (singularity) exists in the data. \n")}
if (errcode[i,1]==32)
{cat(" \n")
cat("ERROR: Models 80 and 81 require between 3 and 6 mediators. \n")}
if (errcode[i,1]==33)
{cat(" \n")
cat("ERROR: Model 82 requires 4 mediators. \n")}
if (errcode[i,1]==34)
{cat(" \n")
cat("ERROR: This model number requires between 2 and 6 mediators. \n")}
if (errcode[i,1]==35)
{cat(" \n")
cat("ERROR: In a model with only one moderator, that moderator must be W. \n")}
if (errcode[i,1]==36)
{cat(" \n")
cat("ERROR: A serial mediation model cannot have more than 6 mediators. \n")}
if (errcode[i,1]==37)
{cat(" \n")
cat("ERROR: No more than 10 mediators are allowed in a PROCESS command. \n")}
if (errcode[i,1]==38)
{cat(" \n")
cat("ERROR: XCATCODE is not provided, not the correct length, or is otherwise invalid. \n")}
if (errcode[i,1]==39)
{cat(" \n")
cat("ERROR: WCATCODE is not provided, not the correct length, or is otherwise invalid. \n")}
if (errcode[i,1]==40)
{cat(" \n")
cat("ERROR: ZCATCODE is not provided, not the correct length, or is otherwise invalid. \n")}
if (errcode[i,1]==41)
{cat(" \n")
cat("ERROR: Models 1, 2, and 3 cannot be customized. \n")}
if (errcode[i,1]==43)
{cat(" \n")
cat("ERROR: PROCESS does not allow dichotomous mediators. \n")}
if (errcode[i,1]==50)
{cat(" \n")
cat("ERROR: A multicategorical moderator cannot be specified as a covariate. \n")}
if (errcode[i,1]==51)
{cat(" \n")
cat("ERROR: A variable you specified as a covariate is a moderator in all equations. \n")}
if (errcode[i,1]==62)
{cat(" \n")
cat("ERROR: After listwise deletion of cases with missing data, too few cases remain. \n")}
if (errcode[i,1]==63)
{cat(" \n")
cat("ERROR: The XMINT option is available only for model 4. \n")}
if (errcode[i,1]==64)
{cat(" \n")
cat("ERROR: Incorrect number of values specified in CDEVAL option. \n")}
if (errcode[i,1]==65)
{cat(" \n")
cat("ERROR: Only indicator or sequential coding of X is allowed with the XMINT option. \n")}
if (errcode[i,1]==66)
{cat(" \n")
cat("ERROR: A reference value of X is required for this model. \n")}
if (errcode[i,1]==67)
{cat(" \n")
cat("ERROR: Too many elements provided in XREFVAL option. \n")}
if (errcode[i,1]==68)
{cat(" \n")
cat("ERROR: Covariate assignment is not allowed with the XMINT option. \n")}
if (errcode[i,1]==69)
{cat(" \n")
cat("ERROR: Incorrect number of values specified in COVAL option. \n")}
if (errcode[i,1]==70)
{cat(" \n")
cat("ERROR: Incorrect value(s) in XREFVAL for this dichotomous X variable. \n")}
if (errcode[i,1]==71)
{cat(" \n")
cat("ERROR: The CENTER option is not available when using the XMINT option. \n")}
if (errcode[i,1]==72)
{cat(" \n")
cat("ERROR: The XMINT option is not available for models with a dichotomous Y. \n")}
if ((errcode[i,1]==52) & (mcerpt==0))
{mcerpt<-1
cat(" \n")
cat("ERROR: A variable specified as multicategorical must have at least three categories. \n")}
if (errcode[i,1]==53)
{cat(" \n")
cat("ERROR: Variables declared as factors are not accepted by PROCESS.\n")}
}
#if (saveboot==1)
#{resultm<-list(resultm,boots)}
#invisible(resultm)
resultms<-NULL
if ((saveboot==0) & (saveest==1)){resultms<-resultm}
if ((saveboot==1) & (saveest==0)){resultms<-boots}
if ((saveboot==1) & (saveest==1)){resultms<-(list(boots,resultm))}
invisible(resultms)
}
process(activate=1)
##
## ******************** PROCESS for R Version 4.2 beta ****************
##
## Written by Andrew F. Hayes, Ph.D. www.afhayes.com
## Documentation available in Hayes (2022). www.guilford.com/p/hayes3
##
## ***********************************************************************
##
## PROCESS is now ready for use.
## Copyright 2022 by Andrew F. Hayes ALL RIGHTS RESERVED
## Workshop schedule at http://haskayne.ucalgary.ca/CCRAM
##
#### Q.2. Mediational Analysis ####
# Read in data
achieve.dat <- read_excel("achieve.xlsx")
# Transform initial data file into tibble
achieve.dat <- as_tibble(achieve.dat)
# M = gelang (general language ability), X = gevocab (vocabulary scores), Y = geread (general reading achievement)
# Get the a coefficient (coefficient of cond = a) and the Im (the intercept of this model)
summary(lm(gelang~gevocab,data=achieve.dat))
##
## Call:
## lm(formula = gelang ~ gevocab, data = achieve.dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.5212 -1.5181 -0.7815 0.6656 10.1005
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.75836 0.05766 30.50 <2e-16 ***
## gevocab 0.70572 0.01135 62.17 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.73 on 10318 degrees of freedom
## Multiple R-squared: 0.2725, Adjusted R-squared: 0.2725
## F-statistic: 3865 on 1 and 10318 DF, p-value: < 2.2e-16
# Get the c' coefficient (coefficient of cond = c') and the b coefficient (coefficient of pmi = b)
# Get the iY from the intercept
summary(lm(geread~gevocab + gelang,data=achieve.dat))
##
## Call:
## lm(formula = geread ~ gevocab + gelang, data = achieve.dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.8593 -1.0194 -0.3517 0.5812 8.8557
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.534352 0.040819 37.59 <2e-16 ***
## gevocab 0.358273 0.009024 39.70 <2e-16 ***
## gelang 0.242694 0.006675 36.36 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.851 on 10317 degrees of freedom
## Multiple R-squared: 0.3699, Adjusted R-squared: 0.3697
## F-statistic: 3028 on 2 and 10317 DF, p-value: < 2.2e-16
# Get the c coefficient (coefficient of cond = c)
summary(lm(geread~gevocab,data=achieve.dat))
##
## Call:
## lm(formula = geread ~ gevocab, data = achieve.dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.2920 -1.1263 -0.4379 0.6148 8.6621
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.961095 0.041522 47.23 <2e-16 ***
## gevocab 0.529546 0.008175 64.78 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.966 on 10318 degrees of freedom
## Multiple R-squared: 0.2891, Adjusted R-squared: 0.2891
## F-statistic: 4196 on 1 and 10318 DF, p-value: < 2.2e-16
# Run process.R
# Now, run mediation model in process
process (data=achieve.dat, y="geread", x="gevocab", m = "gelang", total =1, normal = 1, model = 4, modelbt = 1, boot = 10000, seed = 1234)
##
## ******************** PROCESS for R Version 4.2 beta ****************
##
## Written by Andrew F. Hayes, Ph.D. www.afhayes.com
## Documentation available in Hayes (2022). www.guilford.com/p/hayes3
##
## ***********************************************************************
##
## Model : 4
## Y : geread
## X : gevocab
## M : gelang
##
## Sample size: 10320
##
## Custom seed: 1234
##
##
## ***********************************************************************
## Outcome Variable: gelang
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.5220 0.2725 7.4545 3865.3311 1.0000 10318.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 1.7584 0.0577 30.4967 0.0000 1.6453 1.8714
## gevocab 0.7057 0.0114 62.1718 0.0000 0.6835 0.7280
##
## ***********************************************************************
## Outcome Variable: geread
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.6082 0.3699 3.4273 3027.7601 2.0000 10317.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 1.5344 0.0408 37.5892 0.0000 1.4543 1.6144
## gevocab 0.3583 0.0090 39.7025 0.0000 0.3406 0.3760
## gelang 0.2427 0.0067 36.3572 0.0000 0.2296 0.2558
##
## ************************ TOTAL EFFECT MODEL ***************************
## Outcome Variable: geread
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.5377 0.2891 3.8661 4196.4714 1.0000 10318.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 1.9611 0.0415 47.2303 0.0000 1.8797 2.0425
## gevocab 0.5295 0.0082 64.7802 0.0000 0.5135 0.5456
##
## ***********************************************************************
## Bootstrapping progress:
##
|
| | 0%
|
| | 1%
|
|> | 1%
|
|> | 2%
|
|>> | 2%
|
|>> | 3%
|
|>> | 4%
|
|>>> | 4%
|
|>>> | 5%
|
|>>> | 6%
|
|>>>> | 6%
|
|>>>> | 7%
|
|>>>>> | 7%
|
|>>>>> | 8%
|
|>>>>> | 9%
|
|>>>>>>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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
##
## ************ TOTAL, DIRECT, AND INDIRECT EFFECTS OF X ON Y ************
##
## Total effect of X on Y:
## effect se t p LLCI ULCI
## 0.5295 0.0082 64.7802 0.0000 0.5135 0.5456
##
## Direct effect of X on Y:
## effect se t p LLCI ULCI
## 0.3583 0.0090 39.7025 0.0000 0.3406 0.3760
##
## Indirect effect(s) of X on Y:
## Effect BootSE BootLLCI BootULCI
## gelang 0.1713 0.0066 0.1587 0.1843
##
## Normal theory test for indirect effect(s):
## Effect se Z p
## gelang 0.1713 0.0055 31.3817 0.0000
##
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
##
## Outcome variable: gelang
##
## Coeff BootMean BootSE BootLLCI BootULCI
## constant 1.7584 1.7583 0.0539 1.6525 1.8639
## gevocab 0.7057 0.7057 0.0132 0.6798 0.7317
## ----------
## Outcome variable: geread
##
## Coeff BootMean BootSE BootLLCI BootULCI
## constant 1.5344 1.5340 0.0420 1.4526 1.6168
## gevocab 0.3583 0.3584 0.0115 0.3354 0.3812
## gelang 0.2427 0.2427 0.0085 0.2262 0.2596
##
## ******************** ANALYSIS NOTES AND ERRORS ************************
##
## Level of confidence for all confidence intervals in output: 95
##
## Number of bootstraps for percentile bootstrap confidence intervals: 10000
#### Q3. Moderation Models ####
# Read in data
assign2.dat <- read_excel("Assign2.xlsx")
# Transform initial data file into tibble
assign2.dat <- as_tibble(assign2.dat)
# predicting relationship quality (Tot_PRQCI) from sexual destiny beliefs (SexDestiny), sexual growth beliefs (SexGrowth), sexual disagreement level (SexCompat), and their interactions.
# Model 1
process (data=assign2.dat, y = "Tot_PRQCI", x="SexDestiny", w = "SexCompat", cov=c("SexGrowth"), model=1, jn=1, plot=1, modelbt = 1, boot = 10000, seed = 3526)
##
## ******************** PROCESS for R Version 4.2 beta ****************
##
## Written by Andrew F. Hayes, Ph.D. www.afhayes.com
## Documentation available in Hayes (2022). www.guilford.com/p/hayes3
##
## ***********************************************************************
##
## Model : 1
## Y : Tot_PRQCI
## X : SexDestiny
## W : SexCompat
##
## Covariates:
## SexGrowth
##
## Sample size: 660
##
## Custom seed: 3526
##
##
## ***********************************************************************
## Outcome Variable: Tot_PRQCI
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.3291 0.1083 303.9407 19.8933 4.0000 655.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 98.1512 6.3901 15.3599 0.0000 85.6037 110.6987
## SexDestiny 0.3025 0.2415 1.2527 0.2108 -0.1717 0.7766
## SexCompat -0.9681 0.9571 -1.0116 0.3121 -2.8474 0.9112
## Int_1 -0.1491 0.0583 -2.5581 0.0107 -0.2635 -0.0346
## SexGrowth 0.4761 0.1636 2.9101 0.0037 0.1548 0.7973
##
## Product terms key:
## Int_1 : SexDestiny x SexCompat
##
## Test(s) of highest order unconditional interaction(s):
## R2-chng F df1 df2 p
## X*W 0.0089 6.5438 1.0000 655.0000 0.0107
## ----------
## Focal predictor: SexDestiny (X)
## Moderator: SexCompat (W)
##
## Conditional effects of the focal predictor at values of the moderator(s):
## SexCompat effect se t p LLCI ULCI
## 2.0000 0.0043 0.1431 0.0302 0.9759 -0.2766 0.2852
## 4.0000 -0.2938 0.0990 -2.9690 0.0031 -0.4881 -0.0995
## 5.0000 -0.4429 0.1210 -3.6596 0.0003 -0.6805 -0.2053
##
## Moderator value(s) defining Johnson-Neyman significance region(s):
## Value % below % above
## 3.3623 47.5758 52.4242
##
## Conditional effect of focal predictor at values of the moderator:
## SexCompat effect se t p LLCI ULCI
## 2.0000 0.0043 0.1431 0.0302 0.9759 -0.2766 0.2852
## 2.3000 -0.0404 0.1309 -0.3086 0.7577 -0.2974 0.2166
## 2.6000 -0.0851 0.1200 -0.7091 0.4785 -0.3208 0.1506
## 2.9000 -0.1298 0.1109 -1.1707 0.2421 -0.3476 0.0879
## 3.2000 -0.1746 0.1039 -1.6796 0.0935 -0.3786 0.0295
## 3.3623 -0.1988 0.1012 -1.9636 0.0500 -0.3975 -0.0000
## 3.5000 -0.2193 0.0996 -2.2023 0.0280 -0.4148 -0.0238
## 3.8000 -0.2640 0.0982 -2.6892 0.0073 -0.4568 -0.0712
## 4.1000 -0.3087 0.0999 -3.0914 0.0021 -0.5048 -0.1126
## 4.4000 -0.3534 0.1045 -3.3824 0.0008 -0.5586 -0.1483
## 4.7000 -0.3982 0.1117 -3.5646 0.0004 -0.6175 -0.1788
## 5.0000 -0.4429 0.1210 -3.6596 0.0003 -0.6805 -0.2053
## 5.3000 -0.4876 0.1320 -3.6938 0.0002 -0.7468 -0.2284
## 5.6000 -0.5323 0.1443 -3.6895 0.0002 -0.8157 -0.2490
## 5.9000 -0.5771 0.1575 -3.6628 0.0003 -0.8864 -0.2677
## 6.2000 -0.6218 0.1716 -3.6241 0.0003 -0.9587 -0.2849
## 6.5000 -0.6665 0.1862 -3.5800 0.0004 -1.0321 -0.3009
## 6.8000 -0.7112 0.2012 -3.5342 0.0004 -1.1064 -0.3161
## 7.1000 -0.7559 0.2167 -3.4890 0.0005 -1.1814 -0.3305
## 7.4000 -0.8007 0.2324 -3.4454 0.0006 -1.2570 -0.3444
## 7.7000 -0.8454 0.2483 -3.4041 0.0007 -1.3330 -0.3577
## 8.0000 -0.8901 0.2645 -3.3653 0.0008 -1.4095 -0.3708
##
## Data for visualizing the conditional effect of the focal predictor:
## SexDestiny SexCompat Tot_PRQCI
## 7.0000 2.0000 110.3435
## 12.0000 2.0000 110.3651
## 21.0000 2.0000 110.4040
## 7.0000 4.0000 106.3202
## 12.0000 4.0000 104.8511
## 21.0000 4.0000 102.2067
## 7.0000 5.0000 104.3086
## 12.0000 5.0000 102.0941
## 21.0000 5.0000 98.1081
##
## ***********************************************************************
## Bootstrapping progress:
##
|
| | 0%
|
| | 1%
|
|> | 1%
|
|> | 2%
|
|>> | 2%
|
|>> | 3%
|
|>> | 4%
|
|>>> | 4%
|
|>>> | 5%
|
|>>> | 6%
|
|>>>> | 6%
|
|>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>>>>>>>>>>>>>>>>>>>>>>>>>| 99%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
##
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
##
## Outcome variable: Tot_PRQCI
##
## Coeff BootMean BootSE BootLLCI BootULCI
## constant 98.1512 98.2535 6.1117 86.2275 110.4236
## SexDestiny 0.3025 0.2940 0.3262 -0.3571 0.9163
## SexCompat -0.9681 -1.0068 1.1360 -3.2683 1.1534
## Int_1 -0.1491 -0.1460 0.0848 -0.3097 0.0208
## SexGrowth 0.4761 0.4762 0.1635 0.1572 0.7934
##
## ******************** ANALYSIS NOTES AND ERRORS ************************
##
## Level of confidence for all confidence intervals in output: 95
##
## Number of bootstraps for percentile bootstrap confidence intervals: 10000
##
## W values in conditional tables are the 16th, 50th, and 84th percentiles.
##
## NOTE: Some cases with missing data were deleted. The number of deleted cases was: 25
# Model 2 (centered)
process (data=assign2.dat, y = "Tot_PRQCI", x="SexDestiny", w = "SexCompat", cov=c("SexGrowth") , model=1, jn=1, plot=1, center=1, modelbt = 1, boot = 10000, seed = 3526)
##
## ******************** PROCESS for R Version 4.2 beta ****************
##
## Written by Andrew F. Hayes, Ph.D. www.afhayes.com
## Documentation available in Hayes (2022). www.guilford.com/p/hayes3
##
## ***********************************************************************
##
## Model : 1
## Y : Tot_PRQCI
## X : SexDestiny
## W : SexCompat
##
## Covariates:
## SexGrowth
##
## Sample size: 660
##
## Custom seed: 3526
##
##
## ***********************************************************************
## Outcome Variable: Tot_PRQCI
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.3291 0.1083 303.9407 19.8933 4.0000 655.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 91.1780 4.8901 18.6455 0.0000 81.5759 100.7801
## SexDestiny -0.2475 0.0983 -2.5172 0.0121 -0.4406 -0.0544
## SexCompat -3.0167 0.4516 -6.6796 0.0000 -3.9036 -2.1299
## Int_1 -0.1491 0.0583 -2.5581 0.0107 -0.2635 -0.0346
## SexGrowth 0.4761 0.1636 2.9101 0.0037 0.1548 0.7973
##
## Product terms key:
## Int_1 : SexDestiny x SexCompat
##
## Test(s) of highest order unconditional interaction(s):
## R2-chng F df1 df2 p
## X*W 0.0089 6.5438 1.0000 655.0000 0.0107
## ----------
## Focal predictor: SexDestiny (X)
## Moderator: SexCompat (W)
##
## Conditional effects of the focal predictor at values of the moderator(s):
## SexCompat effect se t p LLCI ULCI
## -1.6894 0.0043 0.1431 0.0302 0.9759 -0.2766 0.2852
## 0.3106 -0.2938 0.0990 -2.9690 0.0031 -0.4881 -0.0995
## 1.3106 -0.4429 0.1210 -3.6596 0.0003 -0.6805 -0.2053
##
## Moderator value(s) defining Johnson-Neyman significance region(s):
## Value % below % above
## -0.3271 47.5758 52.4242
##
## Conditional effect of focal predictor at values of the moderator:
## SexCompat effect se t p LLCI ULCI
## -1.6894 0.0043 0.1431 0.0302 0.9759 -0.2766 0.2852
## -1.3894 -0.0404 0.1309 -0.3086 0.7577 -0.2974 0.2166
## -1.0894 -0.0851 0.1200 -0.7091 0.4785 -0.3208 0.1506
## -0.7894 -0.1298 0.1109 -1.1707 0.2421 -0.3476 0.0879
## -0.4894 -0.1746 0.1039 -1.6796 0.0935 -0.3786 0.0295
## -0.3271 -0.1988 0.1012 -1.9636 0.0500 -0.3975 -0.0000
## -0.1894 -0.2193 0.0996 -2.2023 0.0280 -0.4148 -0.0238
## 0.1106 -0.2640 0.0982 -2.6892 0.0073 -0.4568 -0.0712
## 0.4106 -0.3087 0.0999 -3.0914 0.0021 -0.5048 -0.1126
## 0.7106 -0.3534 0.1045 -3.3824 0.0008 -0.5586 -0.1483
## 1.0106 -0.3982 0.1117 -3.5646 0.0004 -0.6175 -0.1788
## 1.3106 -0.4429 0.1210 -3.6596 0.0003 -0.6805 -0.2053
## 1.6106 -0.4876 0.1320 -3.6938 0.0002 -0.7468 -0.2284
## 1.9106 -0.5323 0.1443 -3.6895 0.0002 -0.8157 -0.2490
## 2.2106 -0.5771 0.1575 -3.6628 0.0003 -0.8864 -0.2677
## 2.5106 -0.6218 0.1716 -3.6241 0.0003 -0.9587 -0.2849
## 2.8106 -0.6665 0.1862 -3.5800 0.0004 -1.0321 -0.3009
## 3.1106 -0.7112 0.2012 -3.5342 0.0004 -1.1064 -0.3161
## 3.4106 -0.7559 0.2167 -3.4890 0.0005 -1.1814 -0.3305
## 3.7106 -0.8007 0.2324 -3.4454 0.0006 -1.2570 -0.3444
## 4.0106 -0.8454 0.2483 -3.4041 0.0007 -1.3330 -0.3577
## 4.3106 -0.8901 0.2645 -3.3653 0.0008 -1.4095 -0.3708
##
## Data for visualizing the conditional effect of the focal predictor:
## SexDestiny SexCompat Tot_PRQCI
## -6.7424 -1.6894 110.3435
## -1.7424 -1.6894 110.3651
## 7.2576 -1.6894 110.4040
## -6.7424 0.3106 106.3202
## -1.7424 0.3106 104.8511
## 7.2576 0.3106 102.2067
## -6.7424 1.3106 104.3086
## -1.7424 1.3106 102.0941
## 7.2576 1.3106 98.1081
##
## ***********************************************************************
## Bootstrapping progress:
##
|
| | 0%
|
| | 1%
|
|> | 1%
|
|> | 2%
|
|>> | 2%
|
|>> | 3%
|
|>> | 4%
|
|>>> | 4%
|
|>>> | 5%
|
|>>> | 6%
|
|>>>> | 6%
|
|>>>> | 7%
|
|>>>>> | 7%
|
|>>>>> | 8%
|
|>>>>> | 9%
|
|>>>>>> | 9%
|
|>>>>>> | 10%
|
|>>>>>>> | 10%
|
|>>>>>>> | 11%
|
|>>>>>>> | 12%
|
|>>>>>>>> | 12%
|
|>>>>>>>> | 13%
|
|>>>>>>>> | 14%
|
|>>>>>>>>> | 14%
|
|>>>>>>>>> | 15%
|
|>>>>>>>>>> | 15%
|
|>>>>>>>>>> | 16%
|
|>>>>>>>>>> | 17%
|
|>>>>>>>>>>> | 17%
|
|>>>>>>>>>>> | 18%
|
|>>>>>>>>>>> | 19%
|
|>>>>>>>>>>>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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 93%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 94%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 94%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 95%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 96%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 96%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 97%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 98%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 98%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 99%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 99%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
##
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
##
## Outcome variable: Tot_PRQCI
##
## Coeff BootMean BootSE BootLLCI BootULCI
## constant 91.1780 91.1776 4.9085 81.4738 100.6418
## SexDestiny -0.2475 -0.2446 0.1154 -0.4753 -0.0220
## SexCompat -3.0167 -3.0131 0.4670 -3.9254 -2.1021
## Int_1 -0.1491 -0.1460 0.0848 -0.3097 0.0208
## SexGrowth 0.4761 0.4762 0.1635 0.1572 0.7934
##
## ******************** ANALYSIS NOTES AND ERRORS ************************
##
## Level of confidence for all confidence intervals in output: 95
##
## Number of bootstraps for percentile bootstrap confidence intervals: 10000
##
## W values in conditional tables are the 16th, 50th, and 84th percentiles.
##
## NOTE: The following variables were mean centered prior to analysis:
## SexCompat SexDestiny
##
## NOTE: Some cases with missing data were deleted. The number of deleted cases was: 25
#### REFERENCE ####
#Sample_n : Whether the participant was in the nationally representative sample (coded as 1) or the Queer sample (coded as 2).
#SexGrowth : Total scores for Sexual Growth Beliefs Subscale (the belief that sexual satisfaction is attained from hard work and effort), scores can range from 5-35
#SexDestiny: Total scores for Sexual Destiny Beliefs Subscale (sexual satisfaction is attained through finding a compatible sexual partner) scores can range from 5-35
#SexCompat: Total scores for sexual compatibility, a measure of how alike or different sexual preferences are between partners. Scores can range from 2-10.
#Tot_PRQCI: Total scores on the Perceived Relationship Quality Component Inventory (a measure of relationship quality). Scores can range from 18 – 126.
#### Moderation by Group ####
process(data=assign2.dat, y="Tot_PRQCI", x="SexDestiny", w="SexCompat", z="Sample_n", cov=c("SexGrowth"), model=3, jn=1, plot=1, center=1, seed=3526, boot=10000, modelbt=1)
##
## ******************** PROCESS for R Version 4.2 beta ****************
##
## Written by Andrew F. Hayes, Ph.D. www.afhayes.com
## Documentation available in Hayes (2022). www.guilford.com/p/hayes3
##
## ***********************************************************************
##
## Model : 3
## Y : Tot_PRQCI
## X : SexDestiny
## W : SexCompat
## Z : Sample_n
##
## Covariates:
## SexGrowth
##
## Sample size: 660
##
## Custom seed: 3526
##
##
## ***********************************************************************
## Outcome Variable: Tot_PRQCI
##
## Model Summary:
## R R-sq MSE F df1 df2 p
## 0.3417 0.1168 302.9154 10.7575 8.0000 651.0000 0.0000
##
## Model:
## coeff se t p LLCI ULCI
## constant 90.8119 4.8930 18.5597 0.0000 81.2040 100.4198
## SexDestiny -0.2244 0.0993 -2.2604 0.0241 -0.4194 -0.0295
## SexCompat -2.9950 0.4575 -6.5463 0.0000 -3.8934 -2.0967
## Int_1 -0.1407 0.0604 -2.3288 0.0202 -0.2593 -0.0221
## Sample_n 2.2671 1.3779 1.6453 0.1004 -0.4385 4.9728
## Int_2 -0.2974 0.1959 -1.5181 0.1295 -0.6821 0.0873
## Int_3 -0.1036 0.9181 -0.1128 0.9102 -1.9064 1.6992
## Int_4 0.1133 0.1201 0.9434 0.3458 -0.1225 0.3490
## SexGrowth 0.4844 0.1637 2.9585 0.0032 0.1629 0.8058
##
## Product terms key:
## Int_1 : SexDestiny x SexCompat
## Int_2 : SexDestiny x Sample_n
## Int_3 : SexCompat x Sample_n
## Int_4 : SexDestiny x SexCompat x Sample_n
##
## Test(s) of highest order unconditional interaction(s):
## R2-chng F df1 df2 p
## X*W*Z 0.0012 0.8900 1.0000 651.0000 0.3458
## ----------
## Focal predictor: SexDestiny (X)
## Moderator: SexCompat (W)
## Moderator: Sample_n (Z)
##
## Data for visualizing the conditional effect of the focal predictor:
## SexDestiny SexCompat Sample_n Tot_PRQCI
## -6.7424 -1.6894 -0.5182 107.1521
## -1.7424 -1.6894 -0.5182 108.4847
## 7.2576 -1.6894 -0.5182 110.8836
## -6.7424 -1.6894 0.4818 112.8895
## -1.7424 -1.6894 0.4818 111.7784
## 7.2576 -1.6894 0.4818 109.7785
## -6.7424 0.3106 -0.5182 103.9579
## -1.7424 0.3106 -0.5182 103.2968
## 7.2576 0.3106 -0.5182 102.1068
## -6.7424 0.3106 0.4818 107.9610
## -1.7424 0.3106 0.4818 105.9887
## 7.2576 0.3106 0.4818 102.4385
## -6.7424 1.3106 -0.5182 102.3609
## -1.7424 1.3106 -0.5182 100.7028
## 7.2576 1.3106 -0.5182 97.7184
## -6.7424 1.3106 0.4818 105.4967
## -1.7424 1.3106 0.4818 103.0938
## 7.2576 1.3106 0.4818 98.7685
##
## ***********************************************************************
## Bootstrapping progress:
##
|
| | 0%
|
| | 1%
|
|> | 1%
|
|> | 2%
|
|>> | 2%
|
|>> | 3%
|
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>>>>>>>>>>>> | 99%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 99%
|
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
##
## ********** BOOTSTRAP RESULTS FOR REGRESSION MODEL PARAMETERS **********
##
## Outcome variable: Tot_PRQCI
##
## Coeff BootMean BootSE BootLLCI BootULCI
## constant 90.8119 90.8225 4.9185 81.2250 100.3574
## SexDestiny -0.2244 -0.2213 0.1156 -0.4511 0.0025
## SexCompat -2.9950 -3.0017 0.4725 -3.9385 -2.0801
## Int_1 -0.1407 -0.1379 0.0824 -0.2977 0.0271
## Sample_n 2.2671 2.2842 1.4001 -0.4112 5.0221
## Int_2 -0.2974 -0.3025 0.2277 -0.7541 0.1360
## Int_3 -0.1036 -0.1155 0.9436 -1.9307 1.7281
## Int_4 0.1133 0.1028 0.1654 -0.2224 0.4242
## SexGrowth 0.4844 0.4840 0.1639 0.1615 0.8019
##
## ******************** ANALYSIS NOTES AND ERRORS ************************
##
## Level of confidence for all confidence intervals in output: 95
##
## Number of bootstraps for percentile bootstrap confidence intervals: 10000
##
## NOTE: The following variables were mean centered prior to analysis:
## SexCompat Sample_n SexDestiny
##
## NOTE: Some cases with missing data were deleted. The number of deleted cases was: 25
#### Moderation - Representative Sample ONLY ####
# Subset for the representative sample (Sample_n == 1)
#representative_data <- subset(assign2.dat, Sample_n == 1)
# Model 1 (Centered) for Representative Sample
#process(data = representative_data, y = "Tot_PRQCI", x = "SexDestiny", w = "SexCompat", cov = c("SexGrowth"), model = 1, jn = 1, plot = 1, center = 1, modelbt = 1, boot = 10000, seed = 3526)
#### Moderation - Queer Sample ONLY ####
#Subset for the queer sample (Sample_n == 2)
#queer_data <- subset(assign2.dat, Sample_n == 2)
# Model 1 (Centered) for Queer Sample (if you have any additional specifications)
#process(data = queer_data, y = "Tot_PRQCI", x = "SexDestiny", w = "SexCompat", cov = c("SexGrowth"), model = 1, jn = 1, plot = 1, center = 1, modelbt = 1, boot = 10000, seed = 3526)