[R] Fractional Factorial - Wrong values using lm-function

Simon Knapp sleepingwell at gmail.com
Mon Jun 25 17:10:14 CEST 2012


and finally...

thingy <- function(x) {
    x <- C(x, poly, 1)
    tmp <- contrasts(x)
    contrasts(x, 1) <- 2 * tmp / sum(abs(tmp))
    x
}

dat2 <- with(data.catapult,
    data.frame(
        Distance,
        h=thingy(h),
        s=thingy(s),
        l=thingy(l),
        e=thingy(e),
        b=thingy(b)
    )
)
lm5 <- lm(Distance ~ .^2, data = dat2)
summary(lm5)




On Tue, Jun 26, 2012 at 12:35 AM, Simon Knapp <sleepingwell at gmail.com> wrote:
> ... but this is tantalisingly close:
>
> dat1 <- with(data.catapult,
>    data.frame(
>        Distance,
>        h=C(h, poly, 1),
>        s=C(s, poly, 1),
>        l=C(l, poly, 1),
>        e=C(e, poly, 1),
>        b=C(b, poly, 1)
>    )
> )
> lm4 <- lm(Distance ~ .^2, data = dat1)
> summary(lm4)
>
> ... wish I knew what it meant.
>
>
>
> On Tue, Jun 26, 2012 at 12:18 AM, Simon Knapp <sleepingwell at gmail.com> wrote:
>> They are coding the variables as factors and using orthogonal
>> polynomial contrasts. This:
>>
>> data.catapult <- data.frame(data.catapult$Distance,
>> do.call(data.frame, lapply(data.catapult[-1], factor, ordered=T)))
>> contrasts(data.catapult$h) <-
>> contrasts(data.catapult$s) <-
>> contrasts(data.catapult$l) <-
>> contrasts(data.catapult$e) <-
>> contr.poly(3, contrasts=F)
>> contrasts(data.catapult$b) <- contr.poly(2, contrasts=F)
>> lm1 <- lm(Distance ~ .^2, data=data.catapult)
>> summary(lm1)
>>
>> gets you closer (same intercept at least), but I can't explain the
>> remaining differences. I'm not even sure why the results to look like
>> they do (interaction terms like "a*b" not "a:b" and one level for each
>> interaction).
>>
>> Hope that helps,
>> Simon Knapp



More information about the R-help mailing list