model plotOk, I am having real trouble in R getting my interaction terms to plot accurately. Firstly here is my glm.
Temp.1<-glm(black ~ abs(Lat) + Alt.1 + Max.1 + abs(Lat):Max.1 + abs(Lat):Alt.1)
My altitude and maximum temperature variables are centred, and I get the following output:
Coefficients:
(Intercept) abs(Lat) Alt.1 Max.1 abs(Lat):Max.1 abs(Lat):Alt.1
51.7399258 -0.4404355 0.0002218 -7.7018000 0.8700034 -0.0015007
I need to plot the results of my model - one showing the effect of proportion blackness with temperature when latitude changes, and one with the difference in proportion blackness with altitude at different latitudes.
The problem I am having is R doesn't seem to plot the models correctly, and is giving me values for blackness above and below my scale of 0-100 (not possible as its a percentage)
This is the code I am using and am completely stuck!
TempA<-seq(-2,5)
TempB<-(TempA+30.35396)
AltA<-seq(60,2000)
LatA<-seq(0,27)
BML<-51.7399258+(-7.7018000*TempA) ## equator
BMLLow<-(51.7399258+(0.6*-0.4404355))+(-7.7018000+(0.8700034*0.6)*TempA)
BMLHigh<-51.7399258+(24*-0.4404355)+(-7.7018000+(0.8700034*24)*TempA)
plot(Max,black, ylim=c(0,100), xlim=c(26,38)
lines(TempB,BML)
lines(TempB,BMLLow, col="red")
lines(TempB,BMLHigh, col="blue")
I would really appreciate all or any help as I have no idea how to fix this!
Thanks in advance
Here is some sample data, I'm afraid I can't share any more but this is the format i have, but I am running the code with the temperature and altitude centred.
dput(Stack[1:10,])
structure(list(Latitude = c(-24.30795, -23.340241, -21.15665,
-21.15665, -17.87762, -17.864179, -17.820673, -17.798579, -17.767033,
-17.755872), Max_Mean = c(31.0208333, 31.0208333, 31.0208333,
31.0208333, 30.7736083, 30.7736083, 30.7736083, 30.7736083, 30.7736083,
30.7736083), Mean_black_pack = c(50.422529, 31.11580776, 34.6917816,
33.86864311, 47.64279486, 3.4046481, 34.26923913, 27.41466269,
18.12089591, 42.71618832), Mean_Alt = c(1197.508352, 1016.849649,
951.0622235, 951.0622235, 978.1990858, 1010.503054, 980.9060909,
982.4801458, 984.3482196, 984.0309493)), .Names = c("Latitude",
"Max_Mean", "Mean_black_pack", "Mean_Alt"), row.names = c(NA,
10L), class = "data.frame")
Thank you for all the help These are the variables as I have them, then for altitude and latitude Alt.1 = centred altitude and Max.1= centred Max_Mean
black<-Stack$Mean_black_pack
Max<-Stack$Max_Mean
Lat<-Stack$Latitude
Alt<-Stack$Mean_Altitude
Alt.1<-Alt-(mean(Alt))
Max.1<-Max-(mean(Max))