data-raw/vishnaadevi.rice.uniformity.R

# vishnaadevi.rice.uniformity.R

libs(desplot,dplyr,kw,lattice,magrittr,readxl,readr,reshape2,tibble)

dat <- matrix(
  c(553,560,562,587,592,592,598,597,595,560,608,560,
    578,566,556,597,583,573,566,578,607,550,600,555,
    578,598,576,605,575,558,575,586,600,559,598,559,
    550,590,588,602,564,586,576,588,610,583,590,558,
    555,587,580,600,560,583,589,608,578,555,569,554,
    589,566,576,593,574,572,580,600,571,565,589,550,
    600,567,575,587,586,570,576,599,574,574,579,561,
    598,587,564,592,573,577,586,567,597,598,577,564,
    578,550,560,584,556,560,592,578,583,587,594,563,
    567,576,566,550,588,555,600,579,593,576,599,569,
    589,556,589,556,566,566,603,569,594,554,588,589,
    590,588,602,560,565,578,602,567,598,590,574,568,
    550,607,605,565,552,598,599,575,574,589,567,585,
    555,575,576,574,560,595,574,570,685,578,588,575,
    589,580,588,581,567,592,583,596,607,558,566,594,
    567,576,576,573,568,589,592,558,605,555,590,567,
    603,567,570,583,570,576,556,590,578,578,594,578,
    605,583,569,577,573,603,590,558,589,583,589,578,
    598,553,565,586,580,592,595,567,596,595,567,598,
    592,596,572,570,567,585,587,576,579,590,589,558,
    580,568,592,575,579,593,576,580,574,578,595,599,
    578,567,573,586,582,586,566,576,595,584,590,567,
    565,572,570,580,590,599,560,589,600,596,568,578,
    577,559,565,584,600,601,568,563,605,605,598,587),
  byrow=TRUE, ncol=12)

dat %<>% as.matrix %>% `colnames<-`(1:ncol(dat)) %>% melt %>% rename(row=Var1,col=Var2,yield=value)

require(desplot)
desplot(dat, yield ~ col*row,
        flip=TRUE, aspect=24/12,
        main="vishnaadevi.rice.uniformity")

vishnaadevi.rice.uniformity <- dat

agex(vishnaadevi.rice.uniformity)

## ---------------------------------------------------------------------------

# Spot-check a couple of the 3x3 moving average values reported in the paper
mean(c(568,567,572, 592,573,570, 575,586,580))
mean(c(575,570,596, 574,685,607, 589,578,558))

# Calculate 3x3 moving average.
libs(desplot, reshape2)
dmat <- melt(dat, id.var=c('col','row'))
dmat <- acast(dmat, row~col)
m0 <- dmat
cx <- 2:(ncol(m0)-1)
rx <- 2:(nrow(m0)-1)
dmat3 <- (m0[rx+1,cx+1]+m0[rx+1,cx]+m0[rx+1,cx-1]+
            m0[rx,cx+1]+m0[rx,cx]+m0[rx,cx-1]+
            m0[rx-1,cx+1]+m0[rx-1,cx]+m0[rx-1,cx-1])/9
dat3 <- melt(dmat3)
desplot(dat3, value~Var2*Var1,
        #aspect=38/18,
        #at=c(576,637,695,753,811,870,927),
        main="vishnaadevi.rice.uniformity moving 3x3 average")
kwstat/agridat documentation built on Nov. 2, 2024, 6:19 a.m.