Last data update: 2014.03.03

R: iterate
iterateR Documentation

iterate

Description

Used by GriegSmith function

Usage

iterate(counts, startingdim)

Arguments

counts
startingdim

Examples



## The function is currently defined as
function(counts,startingdim){


	powers<-c(0:startingdim);
	square<-2^powers;


	x_rects<-sort(c(square,square));
	x_rects<-x_rects[c(-1,-length(x_rects))];

	y_rects0<-2^(1:startingdim);
	y_rects1<-2^(0:(startingdim-1));
	y_rects<-c(rbind(y_rects0,y_rects1));
	
	rects<-rbind(cbind(square,square),cbind(x_rects,y_rects));
	
	
	## rects is a 2 column matrix, the first column is the x length;
	## for each iteration of the G-S method, the second column is the y;
	## width for each iteration. We have both vertically and horizontally;
	## oriented blocks, so we will need to average them. 

	 rects<-rects[order(rowSums(rects)),]

	

	checkhere<-apply(rects,1,sumofsquares,singlecounts=counts);
	mid<-cbind(rects[,1]*rects[,2],rects,checkhere);



	ss<-as.matrix(tapply(mid[,4],mid[,1],mean));
	

	
	ss2<-cbind(ss[-1,1],2*ss[-length(ss),1]);
	blocksize<-as.numeric(rownames(ss2))/2
	rownames(ss2)<-blocksize;





	ssrfinal<-cbind(blocksize,ss2[,2]-ss2[,1],(ss2[,2]-ss2[,1])/(2^(2*startingdim)));


	ssrfinal;

  }

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GriegSmith)
Loading required package: spatstat
Loading required package: nlme
Loading required package: rpart

spatstat 1.45-2       (nickname: 'Caretaker Mode') 
For an introduction to spatstat, type 'beginner' 

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GriegSmith/iterate.Rd_%03d_medium.png", width=480, height=480)
> ### Name: iterate
> ### Title: iterate
> ### Aliases: iterate
> ### Keywords: ~kwd1 ~kwd2
> 
> ### ** Examples
> 
> 
> 
> ## The function is currently defined as
> function(counts,startingdim){
+ 
+ 
+ 	powers<-c(0:startingdim);
+ 	square<-2^powers;
+ 
+ 
+ 	x_rects<-sort(c(square,square));
+ 	x_rects<-x_rects[c(-1,-length(x_rects))];
+ 
+ 	y_rects0<-2^(1:startingdim);
+ 	y_rects1<-2^(0:(startingdim-1));
+ 	y_rects<-c(rbind(y_rects0,y_rects1));
+ 	
+ 	rects<-rbind(cbind(square,square),cbind(x_rects,y_rects));
+ 	
+ 	
+ 	## rects is a 2 column matrix, the first column is the x length;
+ 	## for each iteration of the G-S method, the second column is the y;
+ 	## width for each iteration. We have both vertically and horizontally;
+ 	## oriented blocks, so we will need to average them. 
+ 
+ 	 rects<-rects[order(rowSums(rects)),]
+ 
+ 	
+ 
+ 	checkhere<-apply(rects,1,sumofsquares,singlecounts=counts);
+ 	mid<-cbind(rects[,1]*rects[,2],rects,checkhere);
+ 
+ 
+ 
+ 	ss<-as.matrix(tapply(mid[,4],mid[,1],mean));
+ 	
+ 
+ 	
+ 	ss2<-cbind(ss[-1,1],2*ss[-length(ss),1]);
+ 	blocksize<-as.numeric(rownames(ss2))/2
+ 	rownames(ss2)<-blocksize;
+ 
+ 
+ 
+ 
+ 
+ 	ssrfinal<-cbind(blocksize,ss2[,2]-ss2[,1],(ss2[,2]-ss2[,1])/(2^(2*startingdim)));
+ 
+ 
+ 	ssrfinal;
+ 
+   }
function (counts, startingdim) 
{
    powers <- c(0:startingdim)
    square <- 2^powers
    x_rects <- sort(c(square, square))
    x_rects <- x_rects[c(-1, -length(x_rects))]
    y_rects0 <- 2^(1:startingdim)
    y_rects1 <- 2^(0:(startingdim - 1))
    y_rects <- c(rbind(y_rects0, y_rects1))
    rects <- rbind(cbind(square, square), cbind(x_rects, y_rects))
    rects <- rects[order(rowSums(rects)), ]
    checkhere <- apply(rects, 1, sumofsquares, singlecounts = counts)
    mid <- cbind(rects[, 1] * rects[, 2], rects, checkhere)
    ss <- as.matrix(tapply(mid[, 4], mid[, 1], mean))
    ss2 <- cbind(ss[-1, 1], 2 * ss[-length(ss), 1])
    blocksize <- as.numeric(rownames(ss2))/2
    rownames(ss2) <- blocksize
    ssrfinal <- cbind(blocksize, ss2[, 2] - ss2[, 1], (ss2[, 
        2] - ss2[, 1])/(2^(2 * startingdim)))
    ssrfinal
}
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>