# a quick little example using psuedo likelihood to # estimate the parameters of an auto-logistic model... x_matrix(scan("bintex.dat"),ncol=128) par(mfrow=c(2,2),pty="s") image(x) round(binmple12(x),4) (Intercept) x1 x2 x3 x4 x5 x6 0.1141 0.2977 0.0143 0.1776 -0.0911 -0.0291 0.0325 #source("bintexture.s") # function that determines the maximum psuedo-likelihood # values for a given matrix of binary values. We'll assume # we're using the 12 nearest neighbors (3rd order). This # means 7 coefficients, including the intercept. binmple12_function(x){ n_dim(x)[1]; m_dim(x)[2] # now compute displaced matricies x0_x[c(-1,-2,-(n-1),-n),c(-1,-2,-(m-1),-m)] xr_x[c(-1,-2,-(n-1),-n),c(-1,-2,-3,-m)] xl_x[c(-1,-2,-(n-1),-n),c(-1,-(m-2),-(m-1),-m)] xu_x[c(-1,-(n-2),-(n-1),-n),c(-1,-2,-(m-1),-m)] xd_x[c(-1,-2,-3,-n),c(-1,-2,-(m-1),-m)] xud_x[c(-1,-(n-2),-(n-1),-n),c(-1,-2,-3,-m)] xdu_x[c(-1,-2,-3,-n),c(-1,-(m-2),-(m-1),-m)] xuu_x[c(-1,-(n-2),-(n-1),-n),c(-1,-(m-2),-(m-1),-m)] xdd_x[c(-1,-2,-3,-n),c(-1,-2,-3,-m)] xr2_x[c(-1,-2,-(n-1),-n),c(-1,-2,-3,-4)] xl2_x[c(-1,-2,-(n-1),-n),c(-(m-3),-(m-2),-(m-1),-m)] xu2_x[c(-(n-3),-(n-2),-(n-1),-n),c(-1,-2,-(m-1),-m)] xd2_x[c(-1,-2,-3,-4),c(-1,-2,-(m-1),-m)] x1_as.vector(xr+xl) x2_as.vector(xu+xd) x3_as.vector(xdu+xud) x4_as.vector(xdd+xuu) x5_as.vector(xr2+xl2) x6_as.vector(xu2+xd2) x0_as.vector(x0) pldf_data.frame(x1,x2,x3,x4,x5,x6,x0) a_glm(x0~x1+x2+x3+x4+x5+x6,data=pldf) return(a$coef) }