File: test.clm.flex.link.R

package info (click to toggle)
r-cran-ordinal 2022.11-16-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,856 kB
  • sloc: ansic: 979; sh: 13; makefile: 5
file content (97 lines) | stat: -rw-r--r-- 2,712 bytes parent folder | download | duplicates (2)
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
# test.clm.flex.link.R

library(ordinal)

fm <- clm(rating ~ contact + temp, data=wine, link="log-gamma")
fm
summary(fm)
vcov(fm)
logLik(fm)
extractAIC(fm)
fm2 <- update(fm, link="probit")
anova(fm, fm2)
head(model.matrix(fm)$X)
head(model.frame(fm))
coef(fm)
coef(summary(fm))
nobs(fm)
terms(fm)
# profile(fm) # not implemented
confint(fm)

predict(fm, se=TRUE, interval = TRUE)
predict(fm, type="class")
newData <- expand.grid(temp = c("cold", "warm"),
                       contact = c("no", "yes"))

## Predicted probabilities in all five response categories for each of
## the four cases in newData:
predict(fm, newdata=newData, type="prob")
predict(fm, newdata=newData, type="class")

predict(fm, newdata=newData, type="prob", se.fit = TRUE, interval = TRUE)


## Aranda-Ordaz link:
fm <- clm(rating ~ contact + temp, data=wine, link="Aranda-Ordaz")
fm
summary(fm)
vcov(fm)
logLik(fm)
extractAIC(fm)
fm2 <- update(fm, link="logit")
anova(fm, fm2)
head(model.matrix(fm)$X)
head(model.frame(fm))
coef(fm)
coef(summary(fm))
nobs(fm)
terms(fm)
# profile(fm) # not implemented
confint(fm)

predict(fm, se=TRUE, interval = TRUE)
predict(fm, type="class")
newData <- expand.grid(temp = c("cold", "warm"),
                       contact = c("no", "yes"))

## Predicted probabilities in all five response categories for each of
## the four cases in newData:
predict(fm, newdata=newData, type="prob")
predict(fm, newdata=newData, type="class")

predict(fm, newdata=newData, type="prob", se.fit = TRUE, interval = TRUE)

########################################################################
### Models with scale + flex link (or cauchit link)
########################################################################

fm <- clm(SURENESS ~ PRODID, scale=~PROD, data = soup, link="Aranda-Ordaz")
summary(fm)

fm <- clm(SURENESS ~ PRODID, scale=~PROD, data = soup, link="log-gamma")
summary(fm)

fm <- clm(SURENESS ~ PRODID, scale=~PROD, data = soup, link="cauchit")
summary(fm)

########################################################################
### clm.fit
########################################################################

## Example with log-gamma:
fm1 <- clm(rating ~ contact + temp, data=wine, link="log-gamma")
summary(fm1)
## get the model frame containing y and X:
mf1 <- update(fm1, method="design")
names(mf1)
res <- clm.fit(mf1$y, mf1$X, link="log-gamma") ## invoking the factor method
coef(res)
stopifnot(all.equal(coef(res), coef(fm1)))

## Example with Aranda-Ordaz:
fm1 <- clm(rating ~ contact + temp, data=wine, link="Aranda-Ordaz")
mf1 <- update(fm1, method="design")
res <- clm.fit(mf1$y, mf1$X, link="Aranda") ## invoking the factor method
stopifnot(all.equal(coef(res), coef(fm1)))