
############# ESIMERKKI 3.1 #################################
mesquite <- read.table("http://users.jyu.fi/~junyblom/.dat", header=TRUE)
attach(mesquite)

pairs(mesquite[,c(7,2:6,1)]) # Pisteparvet alkuperäisessä skaalassa

X <- cbind(log(mesquite[,c(7,2:6)]),mesquite[,1])
colnames(X)[7] <- "group"
pairs(X)                     # Pisteparvet logaritmi-skaalassa


## Additiivinen skaala
lm.0 <- lm(leafwt ~ diam1 + diam2 + canht +  totht +  dens + group)
summary(lm.0)


## Logaritminen skaala 
 lm.1 <- lm(log(leafwt) ~ log(diam1) + log(diam2) + log(totht) + 
 log(canht) + log(dens) + group)
 display(lm.1)

## Yksinkertainen malli
 can.vol <- diam1*diam2*canht
 lm.2 <- lm(log(leafwt) ~ log(can.vol) + group)
 display(lm.2)


## Malli A
 lm.A <- lm(log(leafwt) ~ log(diam1) + log(diam2) + log(canht) + group)
 display(lm.A)


## Malli B
 can.area <- diam1*diam2
 can.shape <- diam1/diam2

 lm.B <-  lm(log(leafwt) ~ log(can.area) + log(can.shape) + log(canht) + group)
 display(lm.B)

## Malli C
 lm.C <- lm(log(leafwt) ~ log(can.area) + log(canht) + group)
 display(lm.C)

