Re: [R] Problem in R code

2023-11-09 Thread Ivan Krylov
В Wed, 8 Nov 2023 16:03:15 +0530
Crown Flame  пишет:

> for(i in 1:8)
> {
>   LST_city <- extract(LST, c(lon[i],lat[i]), fun = mean, buffer =
> 1, na.rm = TRUE)   #error
> }

Three things you might need to change:

1. You are trying to assign the output of extract() to the same
variable LST_city in all 8 iterations of the loop. You will probably
need to make it a list and assign to the list elements, e.g.
LST_city[[i]] <- ...

It will also help to learn about lapply() and other functions that
encapsulate loops, although that is more of a matter of taste.

2. You are giving a single vector c(lon[i], lat[i]) to extract() as the
y=... argument. According to help(extract), this is interpreted as
_numbers_ of cells inside x, not coordinates. You should probably
construct a spPolygons() object and use that as the `y` argument to
extract().

3. The description of the 'raster' package says that it's been
superseded by the 'terra' package. You don't have to rewrite all your
code now, but it may be beneficial to check whether 'terra' can
accomplish what you want.

> Error in optim(c(mu_x0, mu_y0, sigma_x0, sigma_y0, amp0), sse) :
>   non-finite value supplied by optim

This must be self-explanatory: your `sse` function returns something
that is not a real number. Try options(error = recover) to see which
arguments it is given when it fails in such a manner. See the free book
"The R Inferno" for more R debugging tips
. Consider
using the 'optimx' package which contains optimisation algorithms that
might work better for you.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problem in R code

2023-11-09 Thread Crown Flame
Good afternoon,
I have been working on my thesis project on the topic "Urban Heat Island
Pattern in India". To achieve the results I am applying a* two-dimensional
Gaussian fit* on an LST raster of 1 km spatial resolution but I am facing
two errors in the following code.

library(raster)
LST <- raster("D:/Celsius_Day/MOD_01.tif")
gaussian2d <- function(x, y, mu_x, mu_y, sigma_x, sigma_y, amp)
{
  exp(-((x - mu_x)^2/(2*sigma_x^2) + (y - mu_y)^2/(2*sigma_y^2)))*amp
}

#define a function for the sum of squared errors between the data and the
Gaussian
sse <- function(p)
{ mu_x <- p
mu_y <- p
sigma_x <- p
sigma_y <- p
amp <- p[5]
fitted <- gaussian2d(x, y, mu_x, mu_y, sigma_x, sigma_y, amp)
sum((z - fitted)^2)
}

#loop over 8 cities
cities <-
c("Delhi","Jaipur","Kolkata","Mumbai","Pune","Hyderabad","Bangalore","Chennai")
lon <-
c(77.219934,75.793261,88.365394,72.900361,73.875199,78.47476,77.602114,80.192181)
lat <-
c(28.589256,26.892024,22.619754,19.110629,18.50269,17.422973,12.974087,13.044415)
results <- data.frame() #A data frame to store the results
for(i in 1:8)
{
  LST_city <- extract(LST, c(lon[i],lat[i]), fun = mean, buffer = 1,
na.rm = TRUE)   #error
}

# Fit a 2D Gaussian surface to the LST data
x <- coordinates(LST)[,1]
y <- coordinates(LST)[,2]
z <- values(LST)
mu_x0 <- mean(x)
mu_y0 <- mean(y)
sigma_x0 <- sd(x)/2
sigma_y0 <- sd(y)/2
amp0 <- max(z)
opt <- optim(c(mu_x0, mu_y0, sigma_x0, sigma_y0, amp0), sse) #error 2

#Calculate the footprint of SUHI effect (FP) by the Gaussian surface
FP <- which(gaussian2d(x, y, opt$par, opt$par, opt$par, opt$par,
opt$par[5]) >= threshold)

#store the results for each city in the data frame
results <- rbind(results, data.frame(city=cities[i], FP=mean(FP)))

#print the results
results


The two errors are in the row which are defining the variables "LST_city"
and "opt".
The first error is:
Error in .cellValues(x, y, ...) : unused arguments (fun =
new("standardGeneric", .Data = function (x, ...) standardGeneric("mean"),
generic = "mean", package = "base", group = list(), valueClass =
character(0), signature = "x", default = new("derivedDefaultMethod", .Data
= function (x, ...) UseMethod("mean"), target = new("signature", .Data =
"ANY", names = "x", package = "methods"), defined = new("signature", .Data
= "ANY", names = "x", package = "methods"), generic = "mean"), skeleton =
(new("derivedDefaultMethod", .Data = function (x, ...) UseMethod("mean"),
target = new("signature", .Data = "ANY", names = "x", package = "methods"),
defined = new("signature", .Data = "ANY", names = "x", package =
"methods"), generic = "mean"))(x, ...)), buffer = 2, na.rm = TRUE)


The second error is:

Error in optim(c(mu_x0, mu_y0, sigma_x0, sigma_y0, amp0), sse) :
  non-finite value supplied by optim



What could be the possible reason behind these errors and most
importantly how can I get rid of these errors?



Thank you


Regards

DD

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-04 Thread thanoon younis
Dear R-Users

After correct some errors in the code below i have only this error

"Error in if (BZ[i] < 0.25) { : missing value where TRUE/FALSE needed"

how can i solve this problem please?



N<-200;P<-9   #Sample size
BZ=matrix(NA, nrow=N, ncol=1)


W=matrix(NA, nrow=N, ncol=1)


for (t in 1:100) {
  #Generate the data for the simulation study
  for (i in 1:N) {

#transform theta to ordered categorical variables


for(j in 1:1){
  if(BZ[i] < 0.25){
W[i] = 1
  }else if(BZ[i] >=0.25 & BZ[i] < 0.5){
W[i] = 2
  }else if(BZ[i] >=0.5 & BZ[i] < 0.75){
W[i] = 3
  }else{
W[i] = 4
  

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-04 Thread Jim Lemon
Hi thanoon,
Well, you have generated a one column matrix of missing values (NA) and
then tried to use those values in a logical test...

Jim

On Wed, Nov 4, 2015 at 8:02 PM, thanoon younis 
wrote:

> Dear R-Users
>
> After correct some errors in the code below i have only this error
>
> "Error in if (BZ[i] < 0.25) { : missing value where TRUE/FALSE needed"
>
> how can i solve this problem please?
>
>
>
> N<-200;P<-9   #Sample size
> BZ=matrix(NA, nrow=N, ncol=1)
>
>
> W=matrix(NA, nrow=N, ncol=1)
>
>
> for (t in 1:100) {
>   #Generate the data for the simulation study
>   for (i in 1:N) {
>
> #transform theta to ordered categorical variables
>
>
> for(j in 1:1){
>   if(BZ[i] < 0.25){
> W[i] = 1
>   }else if(BZ[i] >=0.25 & BZ[i] < 0.5){
> W[i] = 2
>   }else if(BZ[i] >=0.5 & BZ[i] < 0.75){
> W[i] = 3
>   }else{
> W[i] = 4
>   
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Boris Steipe
Why don't you just multiply by four, round, and add one?



B.
On Nov 3, 2015, at 10:02 PM, thanoon younis  wrote:

> Dear R-users
> 
> I have a problem in the code below, the problem is because i want to change
> the variable BZ which is a vector with 200x1 dimension to the var. W which
> is categorical variable with same dimension of BZ but with categorical
> values with 4 categories but i got on only zero values in w why?  any help
> would be appreciated.
> 
> N<-200;P<-9   #Sample size
> BZ=numeric(N)
> 
> W<-numeric(N)
> 
> for (t in 1:1) {
>  #Generate the data for the simulation study
>  for (i in 1:N) {
> 
>#transform theta to ordered categorical variables
> 
> 
>for(j in 1:1){
>  if(BZ[j] < 0.25){
>W[j] = 1
>  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
>W[j] = 2
>  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
>W[j] = 3
>  }else{
>W[j] = 4
>  }}
> 
> 
>#Input data set
>data<-list(N=200,P=9,Q=W)
> 
>  }} #end
> 
> W
> 
> 
> 
> 
> Regards
> 
> 
> -- 
> Thanoon Y. Thanoon
> PhD Candidate
> Department of Mathematical Sciences
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: thanoon.youni...@gmail.com
> E.Mail: dawn_praye...@yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problem in R-code

2015-11-03 Thread thanoon younis
Dear R-users

I have a problem in the code below, the problem is because i want to change
the variable BZ which is a vector with 200x1 dimension to the var. W which
is categorical variable with same dimension of BZ but with categorical
values with 4 categories but i got on only zero values in w why?  any help
would be appreciated.

N<-200;P<-9   #Sample size
BZ=numeric(N)

W<-numeric(N)

for (t in 1:1) {
  #Generate the data for the simulation study
  for (i in 1:N) {

#transform theta to ordered categorical variables


for(j in 1:1){
  if(BZ[j] < 0.25){
W[j] = 1
  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
W[j] = 2
  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
W[j] = 3
  }else{
W[j] = 4
  }}


#Input data set
data<-list(N=200,P=9,Q=W)

  }} #end

W




Regards


-- 
Thanoon Y. Thanoon
PhD Candidate
Department of Mathematical Sciences
Faculty of Science
University Technology Malaysia, UTM
E.Mail: thanoon.youni...@gmail.com
E.Mail: dawn_praye...@yahoo.com
Facebook:Thanoon Younis AL-Shakerchy
Twitter: Thanoon Alshakerchy
H.P:00601127550205

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Boris Steipe
Are you telling me it contains only zeros? Or is it a vector of length zero?

B.


On Nov 3, 2015, at 11:07 PM, thanoon younis  wrote:

> BZ is hidden variable with zero values.
> 
> On 4 November 2015 at 07:02, Boris Steipe  wrote:
> Your approach does not make sense.
> 
> If you initialize a vector as say ...
> 
>BZ <- numeric(5)
> ... what do you _expect BZ contains?
> 
> Also: if you run a loop like you do
> for (j in 1:1) {
>print(j)
> }
> ... what do you _expect_ will happen?
> 
> 
> B.
> 
> On Nov 3, 2015, at 10:43 PM, thanoon younis  
> wrote:
> 
> > Thank you for your response
> >
> > I have a vector of unknown values BZ which is defined already BZ=numeric(N) 
> >  and i want to transfer BZ to ordered categorical variable with 4 
> > categories W but when i write this code
> >
> >   for(j in 1:1){
> >   if(BZ[j] < 0.25){
> > W[j] = 1
> >   }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> > W[j] = 2
> >   }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> > W[j] = 3
> >   }else{
> > W[j] = 4
> >   }}
> >
> > i found the values of W are only 0, but if i change  for(j in 1:N) the 
> > values of W will be only 1. how can i solve this problem?
> > Regards
> >
> > On 4 November 2015 at 06:35, Boris Steipe  wrote:
> > Why don't you just multiply by four, round, and add one?
> >
> >
> >
> > B.
> > On Nov 3, 2015, at 10:02 PM, thanoon younis  
> > wrote:
> >
> > > Dear R-users
> > >
> > > I have a problem in the code below, the problem is because i want to 
> > > change
> > > the variable BZ which is a vector with 200x1 dimension to the var. W which
> > > is categorical variable with same dimension of BZ but with categorical
> > > values with 4 categories but i got on only zero values in w why?  any help
> > > would be appreciated.
> > >
> > > N<-200;P<-9   #Sample size
> > > BZ=numeric(N)
> > >
> > > W<-numeric(N)
> > >
> > > for (t in 1:1) {
> > >  #Generate the data for the simulation study
> > >  for (i in 1:N) {
> > >
> > >#transform theta to ordered categorical variables
> > >
> > >
> > >for(j in 1:1){
> > >  if(BZ[j] < 0.25){
> > >W[j] = 1
> > >  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> > >W[j] = 2
> > >  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> > >W[j] = 3
> > >  }else{
> > >W[j] = 4
> > >  }}
> > >
> > >
> > >#Input data set
> > >data<-list(N=200,P=9,Q=W)
> > >
> > >  }} #end
> > >
> > > W
> > >
> > >
> > >
> > >
> > > Regards
> > >
> > >
> > > --
> > > Thanoon Y. Thanoon
> > > PhD Candidate
> > > Department of Mathematical Sciences
> > > Faculty of Science
> > > University Technology Malaysia, UTM
> > > E.Mail: thanoon.youni...@gmail.com
> > > E.Mail: dawn_praye...@yahoo.com
> > > Facebook:Thanoon Younis AL-Shakerchy
> > > Twitter: Thanoon Alshakerchy
> > > H.P:00601127550205
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > --
> > Thanoon Y. Thanoon
> > PhD Candidate
> > Department of Mathematical Sciences
> > Faculty of Science
> > University Technology Malaysia, UTM
> > E.Mail: thanoon.youni...@gmail.com
> > E.Mail: dawn_praye...@yahoo.com
> > Facebook:Thanoon Younis AL-Shakerchy
> > Twitter: Thanoon Alshakerchy
> > H.P:00601127550205
> 
> 
> 
> 
> -- 
> Thanoon Y. Thanoon
> PhD Candidate 
> Department of Mathematical Sciences 
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: thanoon.youni...@gmail.com
> E.Mail: dawn_praye...@yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Jim Lemon
Hi thanoon,
The problem may lie in your definition of BZ (which I see Boris has also
noticed). Given your code, it will be a vector containing 200 zeros. Your
code will generate 200 ones as zero is less than 0.25. Try defining BZ as
follows:

BZ<-runif(200)

You should get something more interesting from your code or that suggested
by Boris, or even this:

W<-as.numeric(cut(BZ,breaks=c(0,0.25,0.5,0.75,1)))

Jim

On Wed, Nov 4, 2015 at 2:43 PM, thanoon younis 
wrote:

> Thank you for your response
>
> I have a vector of unknown values BZ which is defined already BZ=numeric(N)
>  and i want to transfer BZ to ordered categorical variable with 4
> categories W but when i write this code
>
>   for(j in 1:1){
>   if(BZ[j] < 0.25){
> W[j] = 1
>   }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> W[j] = 2
>   }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> W[j] = 3
>   }else{
> W[j] = 4
>   }}
>
> i found the values of W are only 0, but if i change  for(j in 1:N) the
> values of W will be only 1. how can i solve this problem?
> Regards
>
> On 4 November 2015 at 06:35, Boris Steipe 
> wrote:
>
> > Why don't you just multiply by four, round, and add one?
> >
> >
> >
> > B.
> > On Nov 3, 2015, at 10:02 PM, thanoon younis 
> > wrote:
> >
> > > Dear R-users
> > >
> > > I have a problem in the code below, the problem is because i want to
> > change
> > > the variable BZ which is a vector with 200x1 dimension to the var. W
> > which
> > > is categorical variable with same dimension of BZ but with categorical
> > > values with 4 categories but i got on only zero values in w why?  any
> > help
> > > would be appreciated.
> > >
> > > N<-200;P<-9   #Sample size
> > > BZ=numeric(N)
> > >
> > > W<-numeric(N)
> > >
> > > for (t in 1:1) {
> > >  #Generate the data for the simulation study
> > >  for (i in 1:N) {
> > >
> > >#transform theta to ordered categorical variables
> > >
> > >
> > >for(j in 1:1){
> > >  if(BZ[j] < 0.25){
> > >W[j] = 1
> > >  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> > >W[j] = 2
> > >  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> > >W[j] = 3
> > >  }else{
> > >W[j] = 4
> > >  }}
> > >
> > >
> > >#Input data set
> > >data<-list(N=200,P=9,Q=W)
> > >
> > >  }} #end
> > >
> > > W
> > >
> > >
> > >
> > >
> > > Regards
> > >
> > >
> > > --
> > > Thanoon Y. Thanoon
> > > PhD Candidate
> > > Department of Mathematical Sciences
> > > Faculty of Science
> > > University Technology Malaysia, UTM
> > > E.Mail: thanoon.youni...@gmail.com
> > > E.Mail: dawn_praye...@yahoo.com
> > > Facebook:Thanoon Younis AL-Shakerchy
> > > Twitter: Thanoon Alshakerchy
> > > H.P:00601127550205
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
>
> --
> Thanoon Y. Thanoon
> PhD Candidate
> Department of Mathematical Sciences
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: thanoon.youni...@gmail.com
> E.Mail: dawn_praye...@yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread thanoon younis
Thank you for your response

I have a vector of unknown values BZ which is defined already BZ=numeric(N)
 and i want to transfer BZ to ordered categorical variable with 4
categories W but when i write this code

  for(j in 1:1){
  if(BZ[j] < 0.25){
W[j] = 1
  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
W[j] = 2
  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
W[j] = 3
  }else{
W[j] = 4
  }}

i found the values of W are only 0, but if i change  for(j in 1:N) the
values of W will be only 1. how can i solve this problem?
Regards

On 4 November 2015 at 06:35, Boris Steipe  wrote:

> Why don't you just multiply by four, round, and add one?
>
>
>
> B.
> On Nov 3, 2015, at 10:02 PM, thanoon younis 
> wrote:
>
> > Dear R-users
> >
> > I have a problem in the code below, the problem is because i want to
> change
> > the variable BZ which is a vector with 200x1 dimension to the var. W
> which
> > is categorical variable with same dimension of BZ but with categorical
> > values with 4 categories but i got on only zero values in w why?  any
> help
> > would be appreciated.
> >
> > N<-200;P<-9   #Sample size
> > BZ=numeric(N)
> >
> > W<-numeric(N)
> >
> > for (t in 1:1) {
> >  #Generate the data for the simulation study
> >  for (i in 1:N) {
> >
> >#transform theta to ordered categorical variables
> >
> >
> >for(j in 1:1){
> >  if(BZ[j] < 0.25){
> >W[j] = 1
> >  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> >W[j] = 2
> >  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> >W[j] = 3
> >  }else{
> >W[j] = 4
> >  }}
> >
> >
> >#Input data set
> >data<-list(N=200,P=9,Q=W)
> >
> >  }} #end
> >
> > W
> >
> >
> >
> >
> > Regards
> >
> >
> > --
> > Thanoon Y. Thanoon
> > PhD Candidate
> > Department of Mathematical Sciences
> > Faculty of Science
> > University Technology Malaysia, UTM
> > E.Mail: thanoon.youni...@gmail.com
> > E.Mail: dawn_praye...@yahoo.com
> > Facebook:Thanoon Younis AL-Shakerchy
> > Twitter: Thanoon Alshakerchy
> > H.P:00601127550205
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Thanoon Y. Thanoon
PhD Candidate
Department of Mathematical Sciences
Faculty of Science
University Technology Malaysia, UTM
E.Mail: thanoon.youni...@gmail.com
E.Mail: dawn_praye...@yahoo.com
Facebook:Thanoon Younis AL-Shakerchy
Twitter: Thanoon Alshakerchy
H.P:00601127550205

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Boris Steipe
Your approach does not make sense.

If you initialize a vector as say ...

   BZ <- numeric(5)
... what do you _expect BZ contains?

Also: if you run a loop like you do
for (j in 1:1) {
   print(j)
}
... what do you _expect_ will happen?


B.

On Nov 3, 2015, at 10:43 PM, thanoon younis  wrote:

> Thank you for your response
> 
> I have a vector of unknown values BZ which is defined already BZ=numeric(N)  
> and i want to transfer BZ to ordered categorical variable with 4 categories W 
> but when i write this code
> 
>   for(j in 1:1){
>   if(BZ[j] < 0.25){
> W[j] = 1
>   }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> W[j] = 2
>   }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> W[j] = 3
>   }else{
> W[j] = 4
>   }}
> 
> i found the values of W are only 0, but if i change  for(j in 1:N) the values 
> of W will be only 1. how can i solve this problem?
> Regards
> 
> On 4 November 2015 at 06:35, Boris Steipe  wrote:
> Why don't you just multiply by four, round, and add one?
> 
> 
> 
> B.
> On Nov 3, 2015, at 10:02 PM, thanoon younis  
> wrote:
> 
> > Dear R-users
> >
> > I have a problem in the code below, the problem is because i want to change
> > the variable BZ which is a vector with 200x1 dimension to the var. W which
> > is categorical variable with same dimension of BZ but with categorical
> > values with 4 categories but i got on only zero values in w why?  any help
> > would be appreciated.
> >
> > N<-200;P<-9   #Sample size
> > BZ=numeric(N)
> >
> > W<-numeric(N)
> >
> > for (t in 1:1) {
> >  #Generate the data for the simulation study
> >  for (i in 1:N) {
> >
> >#transform theta to ordered categorical variables
> >
> >
> >for(j in 1:1){
> >  if(BZ[j] < 0.25){
> >W[j] = 1
> >  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> >W[j] = 2
> >  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> >W[j] = 3
> >  }else{
> >W[j] = 4
> >  }}
> >
> >
> >#Input data set
> >data<-list(N=200,P=9,Q=W)
> >
> >  }} #end
> >
> > W
> >
> >
> >
> >
> > Regards
> >
> >
> > --
> > Thanoon Y. Thanoon
> > PhD Candidate
> > Department of Mathematical Sciences
> > Faculty of Science
> > University Technology Malaysia, UTM
> > E.Mail: thanoon.youni...@gmail.com
> > E.Mail: dawn_praye...@yahoo.com
> > Facebook:Thanoon Younis AL-Shakerchy
> > Twitter: Thanoon Alshakerchy
> > H.P:00601127550205
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> 
> -- 
> Thanoon Y. Thanoon
> PhD Candidate 
> Department of Mathematical Sciences 
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: thanoon.youni...@gmail.com
> E.Mail: dawn_praye...@yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Boris Steipe
Sorry, not round. floor()


B.

On Nov 3, 2015, at 10:35 PM, Boris Steipe  wrote:

> Why don't you just multiply by four, round, and add one?
> 
> 
> 
> B.
> On Nov 3, 2015, at 10:02 PM, thanoon younis  
> wrote:
> 
>> Dear R-users
>> 
>> I have a problem in the code below, the problem is because i want to change
>> the variable BZ which is a vector with 200x1 dimension to the var. W which
>> is categorical variable with same dimension of BZ but with categorical
>> values with 4 categories but i got on only zero values in w why?  any help
>> would be appreciated.
>> 
>> N<-200;P<-9   #Sample size
>> BZ=numeric(N)
>> 
>> W<-numeric(N)
>> 
>> for (t in 1:1) {
>> #Generate the data for the simulation study
>> for (i in 1:N) {
>> 
>>   #transform theta to ordered categorical variables
>> 
>> 
>>   for(j in 1:1){
>> if(BZ[j] < 0.25){
>>   W[j] = 1
>> }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
>>   W[j] = 2
>> }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
>>   W[j] = 3
>> }else{
>>   W[j] = 4
>> }}
>> 
>> 
>>   #Input data set
>>   data<-list(N=200,P=9,Q=W)
>> 
>> }} #end
>> 
>> W
>> 
>> 
>> 
>> 
>> Regards
>> 
>> 
>> -- 
>> Thanoon Y. Thanoon
>> PhD Candidate
>> Department of Mathematical Sciences
>> Faculty of Science
>> University Technology Malaysia, UTM
>> E.Mail: thanoon.youni...@gmail.com
>> E.Mail: dawn_praye...@yahoo.com
>> Facebook:Thanoon Younis AL-Shakerchy
>> Twitter: Thanoon Alshakerchy
>> H.P:00601127550205
>> 
>>  [[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in R-code

2015-11-03 Thread Boris Steipe
Whatever -
just type:

W <- floor(BZ * 4) + 1



B.

On Nov 3, 2015, at 11:09 PM, Boris Steipe  wrote:

> Are you telling me it contains only zeros? Or is it a vector of length zero?
> 
> B.
> 
> 
> On Nov 3, 2015, at 11:07 PM, thanoon younis  
> wrote:
> 
>> BZ is hidden variable with zero values.
>> 
>> On 4 November 2015 at 07:02, Boris Steipe  wrote:
>> Your approach does not make sense.
>> 
>> If you initialize a vector as say ...
>> 
>>   BZ <- numeric(5)
>> ... what do you _expect BZ contains?
>> 
>> Also: if you run a loop like you do
>> for (j in 1:1) {
>>   print(j)
>> }
>> ... what do you _expect_ will happen?
>> 
>> 
>> B.
>> 
>> On Nov 3, 2015, at 10:43 PM, thanoon younis  
>> wrote:
>> 
>>> Thank you for your response
>>> 
>>> I have a vector of unknown values BZ which is defined already BZ=numeric(N) 
>>>  and i want to transfer BZ to ordered categorical variable with 4 
>>> categories W but when i write this code
>>> 
>>>  for(j in 1:1){
>>>  if(BZ[j] < 0.25){
>>>W[j] = 1
>>>  }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
>>>W[j] = 2
>>>  }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
>>>W[j] = 3
>>>  }else{
>>>W[j] = 4
>>>  }}
>>> 
>>> i found the values of W are only 0, but if i change  for(j in 1:N) the 
>>> values of W will be only 1. how can i solve this problem?
>>> Regards
>>> 
>>> On 4 November 2015 at 06:35, Boris Steipe  wrote:
>>> Why don't you just multiply by four, round, and add one?
>>> 
>>> 
>>> 
>>> B.
>>> On Nov 3, 2015, at 10:02 PM, thanoon younis  
>>> wrote:
>>> 
 Dear R-users
 
 I have a problem in the code below, the problem is because i want to change
 the variable BZ which is a vector with 200x1 dimension to the var. W which
 is categorical variable with same dimension of BZ but with categorical
 values with 4 categories but i got on only zero values in w why?  any help
 would be appreciated.
 
 N<-200;P<-9   #Sample size
 BZ=numeric(N)
 
 W<-numeric(N)
 
 for (t in 1:1) {
 #Generate the data for the simulation study
 for (i in 1:N) {
 
   #transform theta to ordered categorical variables
 
 
   for(j in 1:1){
 if(BZ[j] < 0.25){
   W[j] = 1
 }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
   W[j] = 2
 }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
   W[j] = 3
 }else{
   W[j] = 4
 }}
 
 
   #Input data set
   data<-list(N=200,P=9,Q=W)
 
 }} #end
 
 W
 
 
 
 
 Regards
 
 
 --
 Thanoon Y. Thanoon
 PhD Candidate
 Department of Mathematical Sciences
 Faculty of Science
 University Technology Malaysia, UTM
 E.Mail: thanoon.youni...@gmail.com
 E.Mail: dawn_praye...@yahoo.com
 Facebook:Thanoon Younis AL-Shakerchy
 Twitter: Thanoon Alshakerchy
 H.P:00601127550205
 
  [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> 
>>> 
>>> 
>>> --
>>> Thanoon Y. Thanoon
>>> PhD Candidate
>>> Department of Mathematical Sciences
>>> Faculty of Science
>>> University Technology Malaysia, UTM
>>> E.Mail: thanoon.youni...@gmail.com
>>> E.Mail: dawn_praye...@yahoo.com
>>> Facebook:Thanoon Younis AL-Shakerchy
>>> Twitter: Thanoon Alshakerchy
>>> H.P:00601127550205
>> 
>> 
>> 
>> 
>> -- 
>> Thanoon Y. Thanoon
>> PhD Candidate 
>> Department of Mathematical Sciences 
>> Faculty of Science
>> University Technology Malaysia, UTM
>> E.Mail: thanoon.youni...@gmail.com
>> E.Mail: dawn_praye...@yahoo.com
>> Facebook:Thanoon Younis AL-Shakerchy
>> Twitter: Thanoon Alshakerchy
>> H.P:00601127550205
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem in r-code

2014-05-09 Thread Suzen, Mehmet
Wrong list. This is an R list not Bugs.
You may want to consult Bugs materials:
http://www2.mrc-bsu.cam.ac.uk/bugs/weblinks/webresource.shtml

On 8 May 2014 11:36, thanoon younis thanoon.youni...@gmail.com wrote:
 dear all members

 is there anyone explain to me the code below and how can i transfer this
 code to winbugs program.

 q[i,1]=qnorm(runif(1,min=.5,max=1),0,1)

 thanks in advance

 thanoon

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problem in r-code

2014-05-08 Thread thanoon younis
dear all members

is there anyone explain to me the code below and how can i transfer this
code to winbugs program.

q[i,1]=qnorm(runif(1,min=.5,max=1),0,1)

thanks in advance

thanoon

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.