
Hi,a slight modification (in your context)  might address your issue.Please let me know if you need any clarification.Mitra Devkota#1library(geoR)baton<-read.table("baton.txt")logsp.geo<-as.geodata(baton,coords.col=8:9,data.col=1)logsp.cloud<-variog(logsp.geo,option="cloud")plot(logsp.cloud,main="Variogram Cloud for logselling price")logsp.variog<-variog(logsp.geo, uvec=seq(0.02,0.15,l=10), option="bin")plot(logsp.variog,pch=20,main="Variogram for logselling price, baton data")#3.fit<-lm(y~x1+x2+x3+x4+x5+x6+x7+x8,data=baton)coefficients(fit)residuals(fit)resid<- matrix(residuals(fit))baton1<-cbind(y,x1,x2,x3,x4,x5,x6,x7,x8,resid)baton1#4.res.geo<-as.geodata(baton1,coords.col=8:9,data.col=10)res.cloud<-variog(res.geo,option="cloud")plot(res.cloud,main="Variogram Cloud for residuals to the least squares fit")res.variog<-variog(res.geo, uvec=seq(0.02,0.15,l=10), option="bin")plot(res.variog,pch=20,main=" Empirical Variogram for residuals to the least squares fit")##5 (using logsp)exp.vg<-variofit(vario=logsp.variog,ini.cov.pars=c(0.02,0.1),nugget=0.1,cov.model="exponential",weights="cressie")summary(exp.vg)plot(logsp.variog, xlab="DISTANCE",ylab="GAMMA",main="Fitted Exponential Variogram Model for log selling price")lines(exp.vg, col="green")#ordinary kriging(exponential)#logsp.grid<-expand.grid(seq(30.19,30.98,l=30),seq(-91.20,-91,l=30))#logsp.krige.exp<-krige.conv(coords=logsp.geo$coords,data=logsp.geo$data,loc=logsp.grid,krige=krige.control(obj.m=exp.vg))#summary(logsp.krige.exp)#image(logsp.krige.exp,loc=logsp.grid,xlim=c(30.38,30.60),ylim=c(-91.20,-91),main="Ordinary kriging using logsp for exponential model")#contour(logsp.krige.exp,loc=logsp.grid,levels=seq(-3.5,3.5,l=32),add=T)#5 (using residuals)exp.vg<-variofit(vario=res.variog,ini.cov.pars=c(0.02,0.1),nugget=0.01,cov.model="exponential",weights="cressie")summary(exp.vg)plot(res.variog, xlab="DISTANCE",ylab="GAMMA",main="Fitted Exponential Variogram Model for residuals")lines(exp.vg, col="blue")#Ordinary kriging(exponential)res.grid<-expand.grid(seq(30.19
,30.98,l=30),seq(-91.20,-91,l=30))res.krige.exp<-krige.conv(coords=res.geo$coords,data=res.geo$data,loc=res.grid,krige=krige.control(obj.m=exp.vg))summary(res.krige.exp)image(res.krige.exp,loc=res.grid,xlim=c(30.38,30.60),ylim=c(-91.20,-91),main="Ordinary kriging using residuals for exponential model")contour(res.krige.exp,loc=res.grid,levels=seq(-0.5,0.5,l=32),add=T)#6. Our fitted regression function is: Yhat=b0+b1*X1+b2*X2+b3*X3+b4*X4+b5*X5+b6*X6+b7*X7+b8X8Yhat


Mitra Devkota

> Date: Sun, 17 Jun 2012 13:00:56 -0700
> From: feimaobaobao@hotmail.com
> To: r-sig-geo@r-project.org
> Subject: [R-sig-Geo] How to get started with matrix data read into R
> 
> Dear R-sig-geo$B!$(B
> 
> I have some house sales data and I want to use universal kriging to predict
> house price at a new location. 
> 
> My data look like this:
> 
> > house.data[1,]
>    houseId  transvalue          transvalue_previous   bathroomcnt bedroomcnt 
>    xxx-1       231000              129500                           2         
> 3      
> builtyear finishedsquarefeet lotsizesquarefeet storycnt     latitude 
> longitude
> 1964               2110              8413                 1        47.469470
> -122.282926
> houseAge                 year_from_last_sale
>     41                        10.91855
> 
> I just read the data into R and don't know how to prepare a data like meuse
> such that I can use krige.
> Can someone point me some manual or thread with detail steps? I didn't find
> the answer in gstat webpage
> 
> http://cran.r-project.org/web/packages/gstat/index.html
> 
> Thanks much!
> 
> Best,
> Lindia
> 
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/How-to-get-started-with-matrix-data-read-into-R-tp7580234.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
 		 	   		  
	[[alternative HTML version deleted]]

