Tuesday, April 17, 2012

Loglinear for Drinking Data (Reshape the original MBdrink dataframe)

> library(icda)
> data(MBdrink)
> MBdrink
EI SN TF JP Drink Count
1 E S T J Often 10
2 E S T P Often 8
3 E S F J Often 5
4 E S F P Often 7
5 E S T J Rarely 67
6 E S T P Rarely 34
7 E S F J Rarely 101
8 E S F P Rarely 72
9 E N T J Often 3
10 E N T P Often 2
11 E N F J Often 4
12 E N F P Often 15
13 E N T J Rarely 20
14 E N T P Rarely 16
15 E N F J Rarely 27
16 E N F P Rarely 65
17 I S T J Often 17
18 I S T P Often 3
19 I S F J Often 6
20 I S F P Often 4
21 I S T J Rarely 123
22 I S T P Rarely 49
23 I S F J Rarely 132
24 I S F P Rarely 102
25 I N T J Often 1
26 I N T P Often 5
27 I N F J Often 1
28 I N F P Often 6
29 I N T J Rarely 12
30 I N T P Rarely 30
31 I N F J Rarely 30
32 I N F P Rarely 73
> library(reshape2)
> New.MBdrink <- dcast(MBdrink, EI + SN + TF + JP ~ Drink, sum)
Using Count as value column: use value.var to override.
> New.MBdrink$total <- New.MBdrink$Rarely + New.MBdrink$Often
> New.MBdrink
EI SN TF JP Rarely Often total
1 E S T J 67 10 77
2 E S T P 34 8 42
3 E S F J 101 5 106
4 E S F P 72 7 79
5 E N T J 20 3 23
6 E N T P 16 2 18
7 E N F J 27 4 31
8 E N F P 65 15 80
9 I S T J 123 17 140
10 I S T P 49 3 52
11 I S F J 132 6 138
12 I S F P 102 4 106
13 I N T J 12 1 13
14 I N T P 30 5 35
15 I N F J 30 1 31
16 I N F P 73 6 79
> Drink.Indep <- glm(total ~ EI + SN + TF + JP, family=poisson, data=New.MBdrink)
> summary(Drink.Indep)

Call:
glm(formula = total ~ EI + SN + TF + JP, family = poisson, data = New.MBdrink)

Deviance Residuals:
Min 1Q Median 3Q Max
-4.3550 -2.1182 -1.0628 0.8506 5.7457

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 4.17712 0.07054 59.216 < 2e-16 ***
EII 0.26439 0.06226 4.246 2.17e-05 ***
SNN -0.87008 0.06765 -12.861 < 2e-16 ***
TFF 0.48551 0.06355 7.640 2.17e-14 ***
JPP -0.12971 0.06185 -2.097 0.036 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 399.94 on 15 degrees of freedom
Residual deviance: 135.87 on 11 degrees of freedom
AIC: 238.7

Number of Fisher Scoring iterations: 4

Tuesday, February 7, 2012

R code of GLMs for Court Data (Poisson Distribution)

> library(icda)
> data(wafers)
> wafers.loglin <- glm(defects ~ trt + thickness, family = poisson(link="log"),data=wafers)
> summary(wafers.loglin)

Call:
glm(formula = defects ~ trt + thickness, family = poisson(link = "log"),
data = wafers)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.2952 -0.6785 -0.2688 0.6776 1.6307

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.7177 0.1602 10.719 < 2e-16 ***
trtB 0.5878 0.1764 3.332 0.000861 ***
thicknesshigh -0.2296 0.1701 -1.349 0.177246
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 27.857 on 19 degrees of freedom
Residual deviance: 14.435 on 17 degrees of freedom
AIC: 94.517

Number of Fisher Scoring iterations: 4

> anova(wafers.loglin, test="Chisq")

Analysis of Deviance Table

Model: poisson, link: log

Response: defects
Terms added sequentially (first to last)

Df Deviance Resid. Df Resid. Dev Pr(>Chi)
NULL 19 27.857
trt 1 11.5894 18 16.268 0.0006633 ***
thickness 1 1.8326 17 14.435 0.1758239
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


> wafCI.LR <- confint(wafers.loglin)
> wafCI.LR
2.5 % 97.5 %
(Intercept) 1.3903205 2.0193444
trtB 0.2469096 0.9400962
thicknesshigh -0.5659614 0.1025576
> wafCI.Wald <- confint.default(wafers.loglin)
> wafCI.Wald
2.5 % 97.5 %
(Intercept) 1.4035823 2.0317207
trtB 0.2420819 0.9334915
thicknesshigh -0.5630535 0.1039046

Wednesday, January 11, 2012

no PUPILTime in java.library.path

Exception in thread "main" java.lang.UnsatisfiedLinkError: no PUPILTime in java.library.path

If you see the above error information you should check your LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}\:${PUPIL_PATH}/lib

Friday, January 6, 2012

Make Sander.PUPIL

if you see this error message

make: *** No rule to make target `mdread.PUPIL.o', needed by `sander.PUPIL'. Stop.

then do

make depend

and then

make SANDER.PUPIL