APA2: APA Style HTML-Tabellen-Ausgabe

Description Usage Arguments Value Examples

View source: R/APA2.R

Description

APA2.matchit print a short summary

Corr1() wird in in APA2 beim Einzelvergeich verwendet.

Die Interne Funktion Corr2() wird in APA2 verwendete um Korrelation zu berechnen.

APA2 erstellt fertigen HTML-Tabellen Output.

Die Funktion APA2.formula estellt die Standard-Tabellen (analog wie die Hmisc:summary). Links stehen die Zielvariablen rechts die Gruppen.

Fie Formel a1 + a2[4] +a3 ~ group1 + group2 ergibt zwei Auswertungen. Die Zahle in eckiger Klammer sind die Nachkommastellen. Achtung die Formeln sind auf 500 zeichen begrenzt (Limitation von der Funktion deparse()) Einstellungen werden global erstellt:

set_my_options(prozent=list(digits=c(1,0), style=2))

get_my_options()$apa.style$prozent

Likert type : c(1, 2), oder c("Freq", "Precent")

Errate korekte Auswertung und Extrahieren der Variablen aus Formula.

Kano: von Kano-Fragebogen.

APA-Methode fuer pwr::pwr.f2.test

APA-Methode fuer meta

Ausgabe von Regressions Tabelle nach der APA-Style vorgabe. Die Funktion ist eine Kopie von texreg aggregate.matrix.

Ordered Logistic or Probit Regression https://stats.idre.ucla.edu/r/dae/ordinal-logistic-regression/

MANOVA: APA2(x, , test="Wilks") test : "Wilks", "Pillai"

Canonical Discriminant Analysis (MANOVA)

Anova- Methode (MANOVA)

LDA (linear discriminants analysis) Erweiterung der MANOVA

APA2.glht multcomp::glht

anova: APA2.aov(x, include.eta = TRUE)

Usage

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
## S3 method for class 'htest'
APA2(x, caption = "", ...)

## S3 method for class 'pairwise.htest'
APA2(x, caption = "", ...)

## S3 method for class 'ICC'
APA2(x, caption = "ICC", note = NULL, type = c(1, 4), output = which_output())

## S3 method for class 'matchit'
APA2(x, ...)

## S3 method for class 'summary.matchit'
APA2(x, ..., digits = 2)

## S3 method for class 'bland_altman'
APA2(
  x,
  caption = paste0("Difference (", x$name.diff, "), Mean (", x$name, ")"),
  note = "",
  ...
)

## S3 method for class 'bland_altman'
print(x)

Corr1(
  y,
  n = nrow(y),
  type = "pearson",
  include.p = FALSE,
  include.stars = TRUE,
  cor_diagonale_up = TRUE,
  dimnames = FALSE
)

Corr2(x, y = NULL, type = "pearson", stars, ...)

APA2(x, ...)

## S3 method for class ''NULL''
APA2(x, ...)

## S3 method for class 'psychobject'
APA2(
  x,
  caption = "",
  note = NULL,
  include.ci = FALSE,
  include.effect = FALSE,
  output = stp25output::which_output(),
  ...
)

## Default S3 method:
APA2(x, ...)

## S3 method for class 'formula'
APA2(
  x,
  data = NULL,
  caption = "",
  fun = NULL,
  type = c("auto", "freq", "mean", "median", "ci", "multiresponse", "cohen.d",
    "effsize", "freq.ci", "describe"),
  note = "",
  na.action = na.pass,
  test = FALSE,
  corr_test = "pearson",
  cor_diagonale_up = TRUE,
  direction = "long",
  order = FALSE,
  decreasing = TRUE,
  use.level = 1,
  include.n = TRUE,
  include.all.n = NULL,
  include.header.n = TRUE,
  include.total = FALSE,
  include.test = test,
  include.p = FALSE,
  include.stars = TRUE,
  include.names = FALSE,
  include.labels = TRUE,
  digits = NULL,
  digits.mean = if (!is.null(digits)) c(digits, digits) else NULL,
  digits.percent = if (is.null(digits)) options()$stp25$apa.style$prozent$digits else
    c(digits, 0),
  output = which_output(),
  ...
)

Recast2_fun(
  x,
  data,
  caption = "",
  fun,
  direction = "long",
  note = "",
  include.n = FALSE,
  ...
)

## S3 method for class 'likert'
APA2(
  x,
  caption = "",
  note = "",
  ReferenceZero = NULL,
  type = "percent",
  include.mean = TRUE,
  na.exclude = FALSE,
  labels = c("low", "neutral", "high"),
  order = FALSE,
  output = which_output(),
  ...
)

errate_statistik2(
  Formula,
  data,
  caption = "caption",
  note = "note",
  type = NULL,
  na.action = na.pass,
  exclude = NA,
  include.n = TRUE,
  include.all.n = NULL,
  include.header.n = TRUE,
  include.total = FALSE,
  include.test = FALSE,
  include.p = TRUE,
  include.stars = FALSE,
  corr_test = "pearson",
  cor_diagonale_up = TRUE,
  max_factor_length = 35,
  order = FALSE,
  decreasing = FALSE,
  useconTest = FALSE,
  normality.test = FALSE,
  digits.mean = options()$stp25$apa.style$m$digits,
  digits.percent = options()$stp25$apa.style$prozent$digits[1],
  test_name = "Hmisc",
  ...
)

## S3 method for class 'fa'
APA2(...)

## S3 method for class 'principal'
APA2(
  x,
  caption = "",
  note = "",
  digits = 2,
  all = FALSE,
  cut = 0.3,
  sort = TRUE,
  suppress.warnings = TRUE,
  ...
)

## S3 method for class 'stp25_reliability'
APA2(x, caption = "", note = "", output = which_output(), ...)

## S3 method for class 'Kano'
APA2(x, caption = "", note = NULL, output = which_output(), ...)

## S3 method for class 'Kano'
print(x, ...)

## S3 method for class 'power.htest'
APA(x, ..., output = which_output())

## S3 method for class 'meta'
APA2(
  x,
  caption = "Meta-analysis",
  note = paste("estimate:", x$sm, x$method.smd),
  include.table = TRUE,
  include.fixed = FALSE,
  include.random = TRUE,
  include.sub = TRUE,
  include.total = TRUE,
  include.heterogeneity = TRUE,
  digits = 2,
  output = which_output(),
  ...
)

## S3 method for class 'list'
APA2(...)

## S3 method for class 'lm'
APA2(
  x,
  caption = NULL,
  note = NULL,
  output = stp25output::which_output(),
  col_names = NULL,
  include.b = TRUE,
  include.se = TRUE,
  include.beta = FALSE,
  include.ci = FALSE,
  include.r = TRUE,
  include.test = FALSE,
  include.eta = TRUE,
  include.sumsq = TRUE,
  include.meansq = FALSE,
  digits.test = 2,
  ci.level = 0.95,
  test.my.fun = FALSE,
  conf.style.1 = TRUE,
  ...
)

## S3 method for class 'glm'
APA2(
  x,
  caption = NULL,
  note = NULL,
  output = stp25output::which_output(),
  col_names = NULL,
  include.b = TRUE,
  include.se = TRUE,
  include.ci = FALSE,
  include.odds = TRUE,
  include.odds.ci = include.ci,
  include.statistic = TRUE,
  include.p = TRUE,
  include.stars = FALSE,
  include.r = TRUE,
  include.pseudo = include.r,
  include.test = FALSE,
  include.rr = FALSE,
  include.rr.ci = include.ci,
  ci.level = 0.95,
  conf.method = "Wald",
  test.my.fun = FALSE,
  conf.style.1 = TRUE,
  digits = 2,
  ...
)

## S3 method for class 'lme'
APA2(...)

## S3 method for class 'lmerMod'
APA2(
  x,
  caption = NULL,
  note = NULL,
  output = stp25output::which_output(),
  col_names = NULL,
  include.b = TRUE,
  include.se = TRUE,
  include.ci = FALSE,
  include.odds = FALSE,
  include.odds.ci = include.ci,
  include.statistic = TRUE,
  include.p = TRUE,
  include.stars = FALSE,
  include.r = TRUE,
  include.pseudo = include.r,
  include.test = FALSE,
  ci.level = 0.95,
  conf.method = "Wald",
  test.my.fun = FALSE,
  conf.style.1 = TRUE,
  digits = 2,
  ...
)

## S3 method for class 'polr'
APA2(
  x,
  caption = NULL,
  note = NULL,
  include.b = TRUE,
  include.se = TRUE,
  include.ci = FALSE,
  include.odds = TRUE,
  ...
)

## S3 method for class 'step'
APA2(
  x,
 
    caption = "Backward elimination of non-significant effects of linear mixed effects model",
  note = "",
  include.se = FALSE,
  include.df = FALSE,
  ...
)

## S3 method for class 'manova'
APA2(
  x,
  test = "Wilks",
  caption = "MANOVA",
  note = "",
  type = c("anova", "manova"),
  include.eta = TRUE,
  output = which_output()
)

## S3 method for class 'candisc'
APA2(x, caption = NA, note = "", output = which_output(), LRtests = TRUE, ...)

## S3 method for class 'Anova.mlm'
APA2(x, caption = NA, note = "", output = which_output(), ...)

## S3 method for class 'lda'
APA2(
  x,
  fit_predict = MASS:::predict.lda(x),
  newdata = model.frame(x),
  caption = "",
  note = "",
  output = which_output(),
  ...
)

## S3 method for class 'TukeyHSD'
APA2(
  x,
  caption = "TukeyHSD",
  note = "",
  output = stp25output::which_output(),
  ...
)

## S3 method for class 'glht'
APA2(
  x,
  caption = "Multiple Comparisons of Means",
  note = "",
  output = stp25output::which_output(),
  include.ci = TRUE,
  level = 0.95,
  ...
)

## S3 method for class 'multicomp'
APA2(x, ...)

## S3 method for class 'anova'
APA2(
  x,
  caption = gsub("\\n", "", paste(attr(x, "heading"), collapse = ", ")),
  note = paste("contrasts: ", paste(options()$contrasts, collapse = ", ")),
  output = stp25output::which_output(),
  include.eta = FALSE,
  include.sumsq = TRUE,
  include.meansq = FALSE,
  ...
)

## S3 method for class 'aov'
APA2(
  x,
  caption = "ANOVA",
  note = paste("contrasts: ", paste(options()$contrasts, collapse = ", ")),
  output = stp25output::which_output(),
  col_names = NULL,
  ...
)

## S3 method for class 'summary.aov'
APA2(
  x,
  caption = "ANOVA",
  note = "",
  output = stp25output::which_output(),
  col_names = NULL,
  ...
)

## S3 method for class 'aovlist'
APA2(x, output = stp25output::which_output(), col_names = NULL, ...)

## S3 method for class 'epi.tests'
APA2(x, ...)

## S3 method for class 'loglm'
APA2(
  x,
  caption = "Likelihood",
  note = "",
  output = stp25output::which_output(),
  col_names = NULL,
  ...
)

## S3 method for class 'summary.table'
APA2(x, ...)

## S3 method for class 'table'
APA2(...)

## S3 method for class 'xtabs'
APA2(
  x,
  caption = "",
  note = "",
  output = stp25output::which_output(),
  digits = NULL,
  include.total = FALSE,
  include.total.columns = FALSE,
  include.total.sub = FALSE,
  include.total.rows = FALSE,
  include.percent = TRUE,
  include.count = TRUE,
  include.margins = TRUE,
  margin = NA,
  add.margins = NA,
  include.correlation = FALSE,
  include.test = FALSE,
  include.sensitivity = FALSE,
  prevalence = NULL,
  ...
)

Arguments

x

epi.tests Objekt

caption, note

Ueberschrift an Output

...

an Output

type

formula: c("auto", "freq", "mean", "median", "ci", "freq.ci") xtabs: type = c("fischer", "odds","sensitivity", "chisquare","correlation", "r")

output

Ausgabe von Ergebiss ueber Output

digits

Nachkommastellen

cor_diagonale_up

bei Correlation art der Formatierung

include.ci

APA2.glht: Cis

data

data.frame wenn x eine Formel ist

fun, na.action, direction

eigene Funktion na.action=na.pass

test, include.test, corr_test, include.p, include.stars

Sig test bei type = auto moegliche Parameter sind test=TRUE, test="conTest" oder "sapiro.test" fuer den Test auf Normalverteilung, fuer SPSS-like test=="wilcox.test" oder test=="kruskal.test" corr_test-ddefault ist "pearson" c("pearson","spearman")

direction

long or wide

order, decreasing

Sortieren Reihenfolge der Sortierung

use.level

Benutzter level in Multi zB ja/nein

include.n, include.all.n, include.header.n, include.total

N mit ausgeben

include.total

Zusammenfassung als Gesamtwert

include.names, include.labels

Beschriftung der zeilen

digits.mean, digits.percent

Nachkommastellen

ReferenceZero, labels, na.exclude, labels, include.mean

Likert: ReferenceZero=2 Neutrales Element in Kombination mit labels = c("low", "neutral", "high") Mittelwerte T/F

max_factor_length, useconTest, normality.test, test_name, exclude, stars, Formula

interne Parameter in erate_statistik

all

APA2.principal if all=TRUE, then the object is declassed and all output from the function is printed

suppress.warnings

APA2.principal Fehlermeldung unterdruecken

include.fixed, include.random

Fixed effect and random effects model:

include.sub

Subgruppen-Analyse

include.se, include.ci, include.odds

SE, 95-Ci, OR noch nicht fertig

include.r, include.pseudo

pseudo R

include.eta

die Manova wird ueber heplots::etasq berechnet und die anova mit den SS eta2=SS/SS_total

ci.level

Ci default 95 Prozent

include.df

df mit ausgeben

LRtests

an candisc::Wilks Wilks Lambda Tests for Canonical Correlations

fit_predict

lda: MASS predict.lda

newdata

lda:model.frame

include.percent, include.count

ausgabe

include.margins

sollen überhaupt Summen (margins) ausgegeben werden die Prozent werden aber wie mit den Margins gerechnet

margin, add.margins

alternative zu include.total

custom.model.names

Namen ner Modelle

include.custom

liste mit Statistiken für Gofs also zB F-Tests

include.ftest, include.loglik

noch nicht fertig

include.aic, include.bic

geht nur zusammen

rgroup

Zwischen Beschriftung

anova_type

bei lme: "F" F-werte (wie SPSS) oder Chi (car::Anova)

caption, note, output, col_names, print_col, labels

an Output

test, type

fischer chi usw

include.total, include.total.columns, include.total.sub, include.total.rows

Zeilen Prozenz usw

Value

html-String ueber cat sowi einen data.frame

liste mit data.frames

invisible data.frame und Output mit html/knit oder Text.

dataframe mit p.werte

data.frame

list(xtab, test)

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
 
require(MatchIt)
require(wakefield)
require(stpvers)
#Projekt("html")


set.seed(0815)

nonMetra <- 702
Metra <- 59

DF3 <- r_data_frame(
  n = nonMetra + Metra,
  d.age = age,
  d.sex = sex,
  r.hcv = rnorm,
  et.dri  = rnorm,
  d.dcd = rnorm,
  d.steatose = answer
)


#+ results='asis'
DF3$metra <- c(rep(0, nonMetra),  rep(1, Metra))
DF3$Metra<- factor(DF3$metra, 0:1,  c("non-Metra", "Metra"))
fm <-  metra ~  d.age + d.sex + r.hcv + et.dri + d.dcd + d.steatose


# 
# m.out <- matchit(fm, data = DF3,   method = "nearest")
# APA2(m.out,caption = "Exact Matching ")
# df.match <- match.data(m.out)
# summary(df.match)





m.out0 <- matchit(fm, data = DF3,   method = "full")
APA2(m.out0,caption = "Matching  method = full")

# m.out1 <- matchit(fm, data = DF3, method = "genetic")
# APA2(m.out1,caption = "Matching method = genetic")

m.out2 <- matchit(fm, data = DF3, method = "optimal", ratio = 1)
APA2(m.out2, caption = "Matching  method = optimal, ratio = 1")

#APA2(summary(m.out0, standardize = TRUE))
# plot(m.out0, type = 'jitter', interactive = FALSE)


df.match0 <- match.data(m.out0)
summary(df.match0)
df.match0 %>% Tabelle2(
  d.age, d.sex, r.hcv, et.dri, d.dcd, d.steatos,
  distance,
  weights,
  subclass,
  by =  ~ Metra,
  APA = TRUE
)

# df.match1 <- match.data(m.out1)
# summary(df.match1)
# df.match1 %>% Tabelle2(
#   d.age, d.sex, r.hcv, et.dri, d.dcd, d.steatos,
#   distance,
#   weights,
#   by =  ~ Metra,
#   APA = TRUE
# )

df.match2 <- match.data(m.out2)
summary(df.match2)
df.match2 %>% Tabelle2(
  d.age, d.sex, r.hcv, et.dri, d.dcd, d.steatos,
  distance,
  weights,
  subclass,
  by =  ~ Metra,
  APA = TRUE
)

#df.match0$subclass 
# End()

#-- Corr1
# APA2(~a+b+cd, data)
#stp25stat:::Corr1(data[1:3], dimnames=TRUE)
#stp25stat:::Corr1(data[1:3], dimnames=TRUE, include.p=TRUE)

#-- Corr2
# APA2(a+b+c~d, data )
#stp25APA2:::Corr2(data[1:3], data[4], "pearson", TRUE)


#-- APA2.formula --
require(stp25data)
APA2(chol0+chol1 ~ g, hyper, print.n=FALSE)
APA2(~ g, hyper, caption="Einfache Tabelle")
APA2(chol0+chol1 ~ g, hyper, caption="Spalte mit Characteristik loeschen", print_col=-2)
APA2(gew + rrs0 ~ g, hyper, print.n=FALSE, test=TRUE)
APA2(~chol0+chol1~chol6+chol12, hyper, caption="Korrelation", test=TRUE)
APA2(~chol0+chol1+chol6+chol12, hyper, caption="Korrelation", test=TRUE, stars=FALSE)




#varana <- varana %>% Label(m1="Mesung1", m2="BMI")
x<-APA2( ~m1,varana)
x<-APA2( ~m1+m2,varana)

x<-APA2( m1~geschl,varana)
x<-APA2( m1+m2~alter,varana)
x<-APA2( m1+m2+geschl~alter,varana, include.test = TRUE)
x<-APA2( ~m1+m2+m3+m4,varana, test=TRUE)


library(lmerTest)

fit1 <- lm(chol0 ~  ak + rrs0 + med + g, hyper)
fit2 <- glm(chol0 ~ med +   ak +   g + rrs0 , hyper, family = poisson())
fit3 <- lmerTest::lmer(chol0 ~ rrs0 + med +  ak  +  (1|g) , hyper )
fits <- list(fit1, fit2, fit3)

APA2(fits,
          custom.model.names=c("lm", "glm", "lmer"),
          digits= list(c(1,2,3,4,5,6,7),
                       c(1,2,3,4,5,6,7),
                       c(1,2,3,4,5,6)),
          include.custom=list(
                       Wald=c("F(1)=245", "F(2)=245","F(3)=245"),
                       Chi=c("X(4)=2.45", "X(5)=24.5","X(6)=24.5")))



 #--- Ordered Logistic or Probit Regression
 require(MASS)
 # options(contrasts = c("contr.treatment", "contr.poly"))
  house.plr <- MASS::polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
  APA2(house.plr, note= APA(house.plr))



summary(lm1 <- lm(Fertility ~ ., data = swiss))
slm1 <- stats::step(lm1)
APA2(slm1)
# require(lmerTest)
 #m <- lmerTest::lmer(
 # Informed.liking ~ Product * Information * Gender +
#  (1 | Consumer) + (1 | Product:Consumer),
#  data = ham
# )
# elimination of non-significant effects
# s <- lmerTest::step(m)

# APA2(s)


#- manova ---------------------------------------------

## Set orthogonal contrasts.
op <- options(contrasts = c("contr.helmert", "contr.poly"))
## Fake a 2nd response variable
npk2 <- within(npk, foo <- rnorm(24))
npk2 <- within(npk2, foo2 <- rnorm(24))
npk2.aov <- manova(cbind(yield, foo, foo2) ~ block + N * P * K, npk2)

APA2(npk2.aov) #wilks
APA2(npk2.aov, "Pillai")

#npk2.aovE <- manova(cbind(yield, foo) ~  N*P*K + Error(block), npk2)
#APA2(npk2.aovE)



 DF<-stp25aggregate::GetData(
"C:/Users/wpete/Dropbox/3_Forschung/R-Project/stp25data/extdata/manova.sav"
)

#information from
DF$GROUP<- factor(DF$GROUP, 1:3, Cs("website", "nurse ", "video tape" ))
#DF %>% Tabelle2(USEFUL, DIFFICULTY, IMPORTANCE, by=~GROUP )

z<- as.matrix(DF[,-1])
fit1<- manova(z ~ DF$GROUP)
APA2(fit1)
summary(fit1)$Eigenvalues

# SPSS
# Multivariate Tests of Significance (S = 2, M = 0, N = 13 )
#
# Test Name       Value  Approx. F Hypoth. DF   Error DF  Sig. of F
#
# Pillais          .48    3.02       6.00      58.00       .012
# Hotellings       .90    4.03       6.00      54.00       .002
# Wilks            .53    3.53       6.00      56.00       .005
# Roys             .47
# Note.. F statistic for WILKS' Lambda is exact.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Univariate F-tests with (2,30) D. F.
#
# Variable   Hypoth. SS   Error SS Hypoth. MS   Error MS          F  Sig. of F
#
# USEFUL       52.92424  293.96544   26.46212    9.79885    2.70053       .083
# DIFFICUL      3.97515  126.28728    1.98758    4.20958     .47216       .628
# IMPORTAN     81.82969  426.37090   40.91485   14.21236    2.87882       .072
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#   Eigenvalues and Canonical Correlations
#
# Root No.    Eigenvalue        Pct.   Cum. Pct.  Canon Cor.
#
# 1          .892      99.416      99.416        .687
# 2          .005        .584     100.000        .072
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





#-- LDA -------------------------

library(MASS)

require(stp25output)


DF2 <- stp25aggregate::GetData(
"C:/Users/wpete/Dropbox/3_Forschung/R-Project/stp25data/extdata/discrim.sav")
#--https://stats.idre.ucla.edu/spss/dae/discriminant-function-analysis/
DF2$Job <- factor(DF2$JOB, 1:3, Cs("customer service", "mechanic","dispatcher"))
DF2$Job2 <- factor(DF2$JOB, c(2,3,1), Cs( "mechanic","dispatcher","customer service"))

#APA2(.~JOB ,DF2)
#DF2 %>%  APA_Correlation(OUTDOOR,SOCIAL,CONSERVATIVE )

fit2 <- lda(Job ~ OUTDOOR+SOCIAL+CONSERVATIVE, data=DF2)
fit3 <- lda(Job2 ~ OUTDOOR+SOCIAL+CONSERVATIVE, data=DF2)

APA2(fit2)
APA2(fit3)

#' #fit2 <- lda(GROUP ~ ., data=DF )
#APA2(fit2)
#plot(fit2)
#----------------------------------------------------------------
# multcomp
#----------------------------------------------------------------
#require(graphics)
#
#-- breaks ~ wool + tension ----------------------
#warpbreaks %>% Tabelle2(breaks, by= ~ wool + tension)
summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks))

#  ANOVA
APA2(fm1, caption="ANOVA")

# TukeyHSD
TukeyHSD(fm1, "tension", ordered = TRUE) %>%
  APA_Table(caption="TukeyHSD" )

#plot(TukeyHSD(fm1, "tension"))
#levels(warpbreaks$tension)

# Lm Split
fm1_split <-  summary(fm1,
                      split=list(tension=list( M=1,  H=3, L=2)),
                      expand.split=FALSE)
APA2(fm1_split)


# Multcomp
require(multcomp)

fit_Tukey <-glht(fm1,
                 linfct=mcp(tension="Tukey"),
                 alternative = "less"
)

APA_Table(fit_Tukey, caption="APA_Table: multcomp mcp Tukey")

APA2(fit_Tukey, caption="APA2: multcomp mcp Tukey")



### contrasts for `tension'
K <- rbind("L - M" = c( 1, -1,  0),
           "M - L" = c(-1,  1,  0),
           "L - H" = c( 1,  0, -1),
           "M - H" = c( 0,  1, -1))

warpbreaks.mc <- glht(fm1,
                      linfct = mcp(tension = K),
                      alternative = "less")
APA2(warpbreaks.mc, caption="APA2: multcomp mcp mit Contrasten")
### correlation of first two tests is -1
cov2cor(vcov(fm1))

### use smallest of the two one-sided
### p-value as two-sided p-value -> 0.0232
summary(fm1)


# -- Interaction ------------------------
summary(fm2 <- aov(breaks ~ wool * tension, data = warpbreaks))
APA_Table(fm2)
x <- TukeyHSD(fm2, "tension",
              ordered = TRUE)
APA2(x, caption="Interaction: TukeyHSD" )



warpbreaks$WW<-interaction(warpbreaks$wool,warpbreaks$tension )
mod2<-aov(breaks~WW, warpbreaks)
APA2(mod2, caption="ANOVA interaction haendich zu den Daten hinzugefuehgt")



library(multcomp)
 ### multiple linear model, swiss data
 lmod <- lm(Fertility ~ ., data = swiss)

 ### test of H_0: all regression coefficients are zero
 ### (ignore intercept)

### define coefficients of linear function directly
K <- diag(length(coef(lmod)))[-1,]
rownames(K) <- names(coef(lmod))[-1]
K
### set up general linear hypothesis
APA2(glht(lmod, linfct = K))


#- ANOVA ---------
# op <- options(contrasts = c("contr.helmert", "contr.poly"))
# npk.aov <- aov(yield ~ block + N*P*K, npk)
#summary(npk.aov)
#coefficients(npk.aov)

#APA2(npk.aov, include.eta = FALSE)


#- One way repeated Measures ---------------------

#datafilename="http://personality-project.org/r/datasets/R.appendix3.data"
#data.ex3=read.table(datafilename,header=T)   #read the data into a table
# #data.ex3                                      #show the data

#aov.ex3 = aov(Recall~Valence+Error(Subject/Valence),data.ex3)
#
#APA2(aov.ex3)


#' library(caret)
require(epiR)
DF<- GetData("
GoldStandart RT.qPCR Anzahl
positiv positiv 111
positiv negativ 12
negativ positiv 1
negativ negativ 62 ", Tabel_Expand =TRUE, id.vars=1:2, output=FALSE)
DF$GoldStandart<- factor( DF$GoldStandart, rev(levels( DF$GoldStandart)))
DF$RT.qPCR<- factor( DF$RT.qPCR, rev(levels( DF$RT.qPCR)))

 


dat <- as.table(matrix(c(111, 12, 1, 62), nrow = 2, byrow = TRUE))
colnames(dat) <- c("RT.qPCR +", "RT.qPCR -")
rownames(dat) <- c("Gold Standart +", "GoldStandart -")
rval <- epi.tests(dat, conf.level = 0.95)
APA2(rval)



# Fit Log-Linear Models by Iterative Proportional Scaling
library(MASS)

fit<-loglm(~ Type + Origin, xtabs(~ Type + Origin, Cars93))
APA2(fit)
#-- APA2.summary.table

a <- letters[1:3]
APA2(summary(table(a, sample(a))))

stp4/stp25stat documentation built on Sept. 17, 2021, 2:03 p.m.