APA2: APA Style HTML-Tabellen-Ausgabe

Description Usage Arguments Value Examples

View source: R/APA.R

Description

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

Errate korekte Auswertung und Extrahieren der Variablen aus Formula.

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

Methode f<c3><bc>r car::durbinWatsonTest Kopie von car:::print.durbinWatsonTest

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

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

Corr1() wird in in APA2 beim Einzelvergeich verwendet.

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

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

LDA (linear discriminants analysis) Erweiterung der MANOVA

APA2.glht multcomp::glht

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
APA2(x, ...)

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

## Default S3 method:
APA2(x, ..., caption = "", output = TRUE)

## 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 = TRUE, ...)

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

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 'ICC'
APA2(x, caption = "ICC", type = c(1, 4))

## 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 = "")

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

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

## S3 method for class 'bland_altman'
APA(x, ...)

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

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

## S3 method for class 'efflist'
APA2(x, caption = "Effekte: ", type = NULL,
  note = "", output = stp25output::which_output(), digits = 2,
  include.fit = TRUE, include.n = FALSE, include.ci = TRUE,
  include.se = FALSE, ...)

## 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 'durbinWatsonTest'
APA2(x,
  caption = "Durbin-Watson Test for Autocorrelated Errors",
  note = NULL, ...)

## S3 method for class 'list'
APA2(x, caption = "", note = "",
  output = stp25output::which_output(), digits = 2,
  custom.model.names = NULL, include.custom = NULL, include.b = TRUE,
  include.ci = FALSE, include.odds = FALSE, include.se = if
  (include.ci) FALSE else TRUE, include.t = FALSE, include.p = FALSE,
  include.stars = if (include.p) FALSE else TRUE,
  include.ftest = FALSE, include.loglik = FALSE,
  include.pseudo = TRUE, include.r = TRUE, include.aic = TRUE,
  include.bic = include.aic, include.sigma = FALSE,
  include.rmse = TRUE, include.gof = TRUE, include.param = TRUE,
  ci.level = 0.95, rgroup = c("Parameter", "Goodness of fit"),
  test.my.fun = FALSE, ...)

## 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,
  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 '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, ...)

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, ...)

## S3 method for class 'manova'
APA2(x, test = "Wilks", caption = "MANOVA",
  note = "", output = c("anova", "manova"))

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

## 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 'summary.survfit'
APA2(fit, digits = NULL, percent = FALSE,
  include = c(time = "time", n.risk = "n.risk", n.event = "n.event", surv
  = "survival", std.err = "std.err", lower = "lower 95% CI", upper =
  "upper 95% CI"), ...)

## S3 method for class 'survfit'
APA2(fit, caption = "NULL", note = "", type = 1,
  digits = 2, ...)

## S3 method for class 'survdiff'
APA2(fit, caption = "Test Survival Curve Differences",
  note = "")

## S3 method for class 'coxph'
APA2(fit, caption = "", note = "", ...)

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

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

## 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(), col_names = NULL,
  print_col = NULL, digits = NULL, test = FALSE, type = c("0",
  "fischer", "odds", "sensitivity", "chisquare", "correlation", "r"),
  include.total = FALSE, include.total.columns = include.total,
  include.total.sub = include.total,
  include.total.rows = include.total, include.percent = TRUE,
  include.count = TRUE, include.margins = TRUE, margin = NA,
  add.margins = NA, labels = NULL, ...)

Arguments

x

Ein R Objekt oder eine Formel oder ein data.frame APA2.list: Liste mit Objekten (fits)

...

weitere Argumente

caption, note

Ueberschrift an Output

output

Ausgabe von Ergebiss ueber Output

data

data.frame wenn x eine Formel ist

fun, na.action, direction

eigene Funktion na.action=na.pass (Auswertung ueeber die Funktionen melt, cast.)

type

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

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")

cor_diagonale_up

bei Correlation art der Formatierung

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, include.total.columns, include.total.sub, include.total.rows

Zeilen Prozenz usw

include.names, include.labels

Beschriftung der zeilen

digits

Nachkommastellen APA2.list: Kommastellen bei uebergabe einer liste muss exakt die Reighenfolge eingehalten werden.

digits.mean, digits.percent

Nachkommastellen

ReferenceZero, labels

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

include.mean

Likert: Mittelwerte T/F

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.ci

APA2.glht: Cis

include.se, include.ci, include.odds

SE, 95-Ci, OR noch nicht fertig

include.df

df mit ausgeben

custom.model.names

Namen ner Modelle

include.custom

liste mit Statistiken f<c3><bc>r Gofs also zB F-Tests

include.ftest, include.loglik

noch nicht fertig

include.r, include.pseudo

pseudo R

include.aic, include.bic

geht nur zusammen

ci.level

Ci default 95 Prozent

rgroup

Zwischen Beschriftung

fit_predict

lda: MASS predict.lda

newdata

lda:model.frame

include.percent, include.count

ausgabe

include.margins

sollen <c3><bc>berhaupt Summen (margins) ausgegeben werden die Prozent werden aber wie mit den Margins gerechnet

margin, add.margins

alternative zu include.total

anova_type

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

caption, note, output, col_names, print_col, labels

an Output

digits

Nachkommastellen

test, type

fischer chi 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

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
#-- APA2.formula --

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)

#End()


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)


 require(stpvers)
 res <-  Reliability(~F3+F2+F10+F11, fkv, check.keys =TRUE)
 APA2(res)
 
 
#----------------------------------------------------------
# Effekte / Mittelwerte

 Tabelle2(fit1, digits=2)  # mean SD
 require(effects)
 fit1 <- lm(chol0 ~  ak + rrs0 + med + g, hyper)
 eff<-allEffects(fit1)
  
 APA2(eff)
 
 #--- Ordered Logistic or Probit Regression 
  options(contrasts = c("contr.treatment", "contr.poly"))
  house.plr <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
  # house.plr
  APA2(house.plr, note= APA(house.plr))


# require(stpvers)
require(lmerTest)
summary(lm1 <- lm(Fertility ~ ., data = swiss))
slm1 <- stats::step(lm1)
APA2(slm1)

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)

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.list(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")))



#- 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)


#-- Corr1
# APA2(~a+b+cd, data)
#stp25APA2:::Corr1(data[1:3], dimnames=TRUE)
#stp25APA2:::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)


#- 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)
#x<-summary(npk2.aov)
APA2(npk2.aov) #wilks
APA2(npk2.aov, "Pillai")

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


 DF<-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)
#fit2 <- lda(GROUP ~ ., data=DF )
#APA2(fit2)
#plot(fit2)



DF2<- 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)
#----------------------------------------------------------------
# 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))


# 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/stp25APA2 documentation built on May 24, 2019, 9:59 p.m.