[R-sig-Geo] 3-year position available in Norway on modelling the distribution of marine species and habitats

2020-10-22 Thread Gonzalez-Mirelis, Genoveva via R-sig-Geo
Maybe this is of interest to the folks in this list. My apologies for 
cross-posting!

We have an exciting, 3-year position available at the Institute of Marine 
Research in Norway under a new project aiming to develop coastal zone maps of 
species and habitats.

You will find all the information that you need on this link:

https://www.jobbnorge.no/en/available-jobs/job/194806/vacant-3-year-research-position-in-the-marine-coastal-zone-mapping-project

Thanks, and feel free to redistribute!

Genoveva Gonzalez Mirelis, Scientist
Institute of Marine Research
Nordnesgaten 50
5005 Bergen, Norway
Phone number +47 55238510


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] [R-sig-eco] raster::predict example doesn't work?

2018-12-05 Thread Gonzalez-Mirelis, Genoveva via R-sig-Geo
Thank you Ákos, your solution does work. One caveat, though: the 'predict' 
function from 'stats' returns a matrix, whereas that from the 'raster' package 
returns a raster object of identical extent and resolution as the supplied 
predictor stack, which is very handy. If no other solutions arise I will just 
convert that matrix to a raster as follows:

r <- raster(ncol=ncol(logo), nrow=nrow(logo))
extent(r) <- extent(logo)
values(r) <- pc


-Original Message-
From: R-sig-ecology  On Behalf Of 
Bede-Fazekas Ákos
Sent: 4. desember 2018 16:50
To: r-sig-ecol...@r-project.org; R-sig-geo 
Subject: Re: [R-sig-eco] raster::predict example doesn't work?

Dear Genoveva,

All the examples in the help file of package 'party' 
(https://cran.r-project.org/web/packages/party/party.pdf) use the function 
predict() from package 'stats' instead of package 'raster'.
But converting the RasterStack to data.frame, changing the column 'red' 
from numeric to factor, using stats::predict(..., newdata), and create a new 
layer of the RasterStack can solve the problem.
logo_df <- as.data.frame(logo)
logo_df$red <- factor(logo_df$red, levels = levels(v$red)) pc <- 
stats::predict(m, OOB = TRUE, newdata = logo_df) logo$pc <- pc

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences


2018.12.04. 15:52 keltezéssel, Gonzalez-Mirelis, Genoveva írta:
> Dear list,
>
> I posted this question recently on another list so I apologize for any 
> cross-posting. Still no solution.
>
>
> I would like to use the 'predict' function in the 'raster' package in an 
> implementation of species distribution modelling with a couple of factor 
> variables. Furthermore, I would like to set this up exactly as the cforest 
> example listed in the help file. Unfortunately, I cannot get the example to 
> work!
>
>
>
> # create a RasterStack or RasterBrick with with a set of predictor 
> layers
>
>
>
> logo <- brick(system.file("external/rlogo.grd", package="raster"))
>
> names(logo)
>
>
>
> # known presence and absence points
>
> p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85,
>
>66, 42, 26, 4, 19, 17, 7, 14, 26, 29, 39, 45, 51, 56, 
> 46, 38, 31,
>
>22, 34, 60, 70, 73, 63, 46, 43, 28), ncol=2)
>
>
>
> a <- matrix(c(22, 33, 64, 85, 92, 94, 59, 27, 30, 64, 60, 33, 31, 9,
>
>99, 67, 15, 5, 4, 30, 8, 37, 42, 27, 19, 69, 60, 73, 3, 
> 5, 21,
>
>37, 52, 70, 74, 9, 13, 4, 17, 47), ncol=2)
>
>
>
> # extract values for points
>
> xy <- rbind(cbind(1, p), cbind(0, a))
>
> v <- data.frame(cbind(pa=xy[,1], extract(logo, xy[,2:3])))
>
>
>
> # cforest (other Random Forest implementation) example with factors 
> argument
>
>
>
> v$red <- as.factor(round(v$red/100))
>
> logo$red <- round(logo[[1]]/100)
>
>
>
> library(party)
>
> m <- cforest(pa~., control=cforest_unbiased(mtry=3), data=v) f <- 
> list(levels(v$red))
>
> names(f) <- 'red'
>
> pc <- predict(logo, m, OOB=TRUE, factors=f)
>
>
>
> # Error in v[cells, ] <- predv :
>
> # number of items to replace is not a multiple of replacement length
>
>
>
> # If you change the order of the first two arguments (I read this somewhere) 
> then the error changes, like this:
>
>
>
> pc <- predict(m, logo, OOB=TRUE, factors=f)
>
>
>
> # Error in RET@prediction_weights(newdata = newdata, mincriterion = 
> mincriterion,  :
>
> # unused argument (factors = f)
>
>
>
> # Lastly, if I run the line without the 'factors' argument
>
> pc <- predict(m, logo, OOB=TRUE)
>
>
>
> # Then I get no errors, but I don't understand the result. It's a 
> vector of 40 values (predictions?)
>
>
>
> I am using Package 'raster' version 2.6-7 in RStudio 1.1.453, running off a 
> server. I have tried the on several other computers, though, and the error 
> persisted.
>
>
>
> Many thanks for any help,
>
>
>
> Genoveva
>
> Genoveva Gonzalez Mirelis, Scientist
> Institute of Marine Research
> Nordnesgaten 50
> 5005 Bergen, Norway
> Phone number +47 55238510
>
>
> Genoveva Gonzalez Mirelis, Scientist
> Institute of Marine Research
> Nordnesgaten 50
> 5005 Bergen, Norway
> Phone number +47 55238510
>
>
>   [[alternative HTML version deleted]]
>
> ___
> R-sig-ecology mailing list
> r-sig-ecol...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

___
R-sig-ecology mailing list
r-sig-ecol...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Unable to use factors in raster::predict

2018-11-20 Thread Gonzalez-Mirelis, Genoveva via R-sig-Geo
Dear list,

I would like to use the 'predict' function in the 'raster' package in an 
implementation of species distribution modelling with a couple of factor 
variables. My case can be set up exactly as the cforest example listed in the 
help file. Unfortunately, I cannot get the example to work: it throws an error 
because of the unused argument 'factors', which I need. Here is the code I am 
referring to:

# create a RasterStack or RasterBrick with with a set of predictor layers
logo <- brick(system.file("external/rlogo.grd", package="raster"))
names(logo)

# known presence and absence points
p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85,
  66, 42, 26, 4, 19, 17, 7, 14, 26, 29, 39, 45, 51, 56, 46, 38, 31,
  22, 34, 60, 70, 73, 63, 46, 43, 28), ncol=2)

a <- matrix(c(22, 33, 64, 85, 92, 94, 59, 27, 30, 64, 60, 33, 31, 9,
  99, 67, 15, 5, 4, 30, 8, 37, 42, 27, 19, 69, 60, 73, 3, 5, 21,
  37, 52, 70, 74, 9, 13, 4, 17, 47), ncol=2)

# extract values for points
xy <- rbind(cbind(1, p), cbind(0, a))
v <- data.frame(cbind(pa=xy[,1], extract(logo, xy[,2:3])))

# cforest (other Random Forest implementation) example with factors argument

v$red <- as.factor(round(v$red/100))
logo$red <- round(logo[[1]]/100)

library(party)
m <- cforest(pa~., control=cforest_unbiased(mtry=3), data=v)
f <- list(levels(v$red))
names(f) <- 'red'
pc <- predict( m,logo, OOB=TRUE, factors=f)

Error in RET@prediction_weights(newdata = newdata, mincriterion = mincriterion, 
 :
  unused argument (factors = f)


Note that I needed to change the order in the arguments in the last line. If I 
run it the way it was in the example, like this:

pc <- predict(logo, m, OOB=TRUE, factors=f)


then the error is the following:


Error in v[cells, ] <- predv :

  number of items to replace is not a multiple of replacement length

Also note that if I run the line without the 'factors' argument the resulting 
value (r) is a matrix, and not a raster object.

I am using Package 'raster' version 2.6-7 on Windows 7 (where this worked fine 
in the past).

Many thanks for any help,

Genoveva

Genoveva Gonzalez Mirelis, Scientist
Institute of Marine Research
Nordnesgaten 50
5005 Bergen, Norway
Phone number +47 55238510


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] problem with predict() in package raster and factor variables

2016-05-01 Thread Gonzalez-Mirelis Genoveva
Dear Frede and list,

My sincere apologies for not providing sufficient information or reproducible 
example. As a matter of fact, you are right and when I looked further into the 
data I used to estimate the random forest model I solved the problem myself! In 
case it's of interest, the problem was that the variable had to be converted to 
a factor *before* fitting the model, so that the result of str(v) should not be 
what I showed in my original mail, but instead it should be:

'data.frame':   1257 obs. of  15 variables:
 $ RefNo  : int  16 16 16 16 17 17 17 17 18 18 ...
 $ PointID: int  1 2 3 4 5 6 7 8 9 10 ...
 $ Count  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ PA : int  0 0 0 0 0 0 0 0 0 0 ...
 $ split  : chr  "T" "T" "T" "T" ...
 $ bathy20_1  : num  256 260 252 266 281 ...
 $ TerClass   : Factor w/ 6 levels "1","2","3","4",..: 2 2 1 1 1 2 1 1 3 3 ...

etc

Note that before, $TerClass was num, and now it's Factor w/ 6 levels

And f should look like this:

$TerClass
[1] "1" "2" "3" "4" "5" "6"

Then the predict() function works without any problems!

Furthermore, there is an example in the help file that exactly represents my 
case, namely this bit:

# create a RasterStack or RasterBrick with with a set of predictor layers
logo <- brick(system.file("external/rlogo.grd", package="raster"))
# known presence and absence points
p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85, 
  66, 42, 26, 4, 19, 17, 7, 14, 26, 29, 39, 45, 51, 56, 46, 38, 31, 
  22, 34, 60, 70, 73, 63, 46, 43, 28), ncol=2)
a <- matrix(c(22, 33, 64, 85, 92, 94, 59, 27, 30, 64, 60, 33, 31, 9,
  99, 67, 15, 5, 4, 30, 8, 37, 42, 27, 19, 69, 60, 73, 3, 5, 21,
  37, 52, 70, 74, 9, 13, 4, 17, 47), ncol=2)
# extract values for points
xy <- rbind(cbind(1, p), cbind(0, a))
v1 <- data.frame(cbind(pa=xy[,1], extract(logo, xy[,2:3])))
# cforest (other Random Forest implementation) example with factors argument
v1$red <- as.factor(round(v1$red/100))
logo$red <- round(logo[[1]]/100)
library(party)
m <- cforest(pa~., control=cforest_unbiased(mtry=3), data=v1)
f1 <- list(levels(v1$red))
names(f1) <- 'red'
pc <- predict(logo, m, OOB=TRUE, factors=f1)

Thank you all very much, and my apologies for wasting anyone's time.

Genoveva

 

From: Frede Aakmann Tøgersen <fr...@vestas.com>
Sent: Sunday, May 1, 2016 6:42 AM
To: Gonzalez-Mirelis Genoveva; r-sig-geo@r-project.org
Subject: RE: [R-sig-Geo] problem with predict() in package raster and factor
variables

Hi Genoveva

You haven't got a response to your question mainly due to a) missing 
information and b) missing reproducible example.

If you had provided the missing information I guess you would have solved the 
problem yourself.

I have never used raster::predict() but having a look at man for that function 
and you error message there is probably some differences between the data used 
to estimate the random forest model (you call that a subset of the object 'v') 
and the data in 'subbrick'. You should provide the structure of data used to 
fit the random forest model and 'subbrick':


> str(v)
> str(subbrick)

Please also show all the relevant R code to obtain what you want in case the 
error message is not related to difference in the creation of the subset of 'v' 
and 'subbrick'


Yours sincerely / Med venlig hilsen

Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.



-Original Message-
From: R-sig-Geo [mailto:r-sig-geo-boun...@r-project.org] On Behalf Of 
Gonzalez-Mirelis Genoveva
Sent: 30. april 2016 12:33
To: r-sig-geo@r-project.org
Subject: [R-sig-Geo] problem with predict() in package raster and factor 
variables

Dear list,
I am trying to use the function predict() (in package raster), where I supply: 
the new data as a RasterBrick, the model (as fit in previous steps and using a 
different dataset), and a few more arguments including the levels of my only 
one categorical value. Here is the code I'm using:

 r1 <- predict(subbrick,
  CIF.pa,
  type="response", OOB=T, factors=f)

But I keep getting the following error:

Error in checkData(oldData, RET) :

  Classes of new data do not match original data

Here are more details:

> CIF.pa

 Random Forest using Conditional Inference Trees

Number of trees:  1000

Response:  PA
Inputs:  bathy20_1, TerClass, Smax_an

[R-sig-Geo] problem with predict() in package raster and factor variables

2016-04-30 Thread Gonzalez-Mirelis Genoveva
Dear list,
I am trying to use the function predict() (in package raster), where I supply: 
the new data as a RasterBrick, the model (as fit in previous steps and using a 
different dataset), and a few more arguments including the levels of my only 
one categorical value. Here is the code I'm using:

 r1 <- predict(subbrick,
  CIF.pa,
  type="response", OOB=T, factors=f)

But I keep getting the following error:

Error in checkData(oldData, RET) :

  Classes of new data do not match original data

Here are more details:

> CIF.pa

 Random Forest using Conditional Inference Trees

Number of trees:  1000

Response:  PA
Inputs:  bathy20_1, TerClass, Smax_ann, Smean_ann, Smin_ann, SPDmax_ann, 
SPDmean_ann, Tmax_ann, Tmean_ann, Tmin_ann
Number of observations:  986

Where 'TerClass' is a categorical variable.

Here is the data used to train CIF.pa:


> str(v)

'data.frame':   1257 obs. of  15 variables:

 $ RefNo  : int  16 16 16 16 17 17 17 17 18 18 ...

 $ PointID: int  1 2 3 4 5 6 7 8 9 10 ...

 $ Count  : int  0 0 0 0 0 0 0 0 0 0 ...

 $ PA : int  0 0 0 0 0 0 0 0 0 0 ...

 $ split  : chr  "T" "T" "T" "T" ...

 $ bathy20_1  : num  256 260 252 266 281 ...

 $ TerClass   : num  2 2 1 1 1 2 1 1 3 3 ...

 $ Smax_ann   : num  35.1 35.1 35.1 35.1 35.1 ...

 $ Smean_ann  : num  35.1 35.1 35.1 35.1 35.1 ...

 $ Smin_ann   : num  34.9 34.9 34.9 34.9 35 ...

 $ SPDmax_ann : num  0.379 0.376 0.378 0.372 0.352 ...

 $ SPDmean_ann: num  0.14 0.137 0.14 0.132 0.12 ...

 $ Tmax_ann   : num  6.97 6.92 7.04 6.87 6.68 ...

 $ Tmean_ann  : num  5.76 5.73 5.79 5.71 5.54 ...

 $ Tmin_ann   : num  4.41 4.32 4.52 4.25 4.07 ...



But actually, I used a subset of v to train the model, that where v$split=='T'

Below are the values and class for TerClass for that subset



> unique(v[v$split=='T',7])

[1] 2 1 3 4 6 5

> class(v$TerClass)

[1] "numeric"

And below are the values and class for the corresponding layer of the 
RasterBrick:

> unique(values(subbrick$TerClass))

[1] 3 1 2 4 5 6

> class(values(subbrick$TerClass))

[1] "numeric"

And finally, here is what f looks like:


> f
$TerClass
[1] 2 1 3 4 6 5

> class(f)
[1] "list"


As far as I can see the classes in OldData and NewData should be the same, but 
the error persists. Any ideas on what I could be missing?

Unfortunately I am unable to reproduce the problem (I only encounter it when 
using my data), but any help will be hugely appreciated

Also, I am aware that I asked this question before (Apr 04, 2013; 1:22pm). 
Unfortunately I haven't gotten very far since then!

Many thanks in advance for any pointers.

Genoveva

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] help- raster overlap (Charbel Eliane)

2013-04-08 Thread Gonzalez-Mirelis Genoveva
Hi Eliane,
Not sure that it will work, but I would recommend converting your raster layers 
to .tiff files prior to importing them into R. Then try

aa-raster('C:/QA_soil/inttotalrain.tif',datatype=INT1U) 

(note the file extension, and data type argument).
Good luck!
Geno

hi list,

i am using R 2.15.3 (64 bit)

i want to stack several raster objects to use for prediction purposes. All
my raster files are integer and has attribute tables and none has NA
values. ( i checked it in arcgis).however when i try to import the raster
to R and check the values in each raster, the only values that i get are
NAs. I hope the example below will clarify more the problem i am facing.
Has anymore encountered a similar problem before? i appreciate any
suggestion. Thanks in advance.

PS: i am able to stack the raster files as well as plot them or compare
them and even predict with it. however with predict i get the message:
Error in .getRat(ratvalues, ratnames, rattypes) :
  argument rattypes is missing, with no default

example:

 a-C:/QA_soil/inttotalrain
 aa-raster(a)
 head(aa)
1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
1  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
2  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
3  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
4  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
5  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
6  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
7  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
8  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
9  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
10 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

 tail(aa)
  15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320
15321
18689NANANANANANANANANANANA
 NA
18690NANANANANANANANANANANA
 NA
18691NANANANANANANANANANANA
 NA
18692NANANANANANANANANANANA
 NA
18693NANANANANANANANANANANA
 NA
18694NANANANANANANANANANANA
 NA
18695NANANANANANANANANANANA
 NA
18696NANANANANANANANANANANA
 NA
18697NANANANANANANANANANANA
 NA
18698NANANANANANANANANANANA
 NA
  15322 15323 15324 15325 15326 15327 15328 15329
18689NANANANANANANANA
18690NANANANANANANANA
18691NANANANANANANANA
18692NANANANANANANANA
18693NANANANANANANANA
18694NANANANANANANANA
18695NANANANANANANANA
18696NANANANANANANANA
18697NANANANANANANANA
18698NANANANANANANANA
  aa
class   : RasterLayer
dimensions  : 18698, 15329, 286621642  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent  : 685798.3, 839088.3, 3658405, 3845385  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=36 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0
+units=m +no_defs
data source : C:\QA_soil\inttotalrain
names   : inttotalrain
values  : 6, 1467  (min, max)
attributes  :
 ID COUNT
 from:6   285
 to  : 146755


On Tue, Feb 19, 2013 at 3:08 PM, Charbel Eliane enchar...@gmail.com wrote:

 Dear list,

 I have 2 raster that represent exactly the same area. the 2 raster have
 the same coordinate system and the same resolution but 2 different origins
 and extents. They are both float. My goal is to perfectly overlap the 2
 rasters, so i can use it for analysis.
 I have tried to use resample in R, to resample one raster using the other
 but the output raster doesn't perfectly overlap with the raster that i used
 to resample to [y in resample (x,y)]. the dim of the resultant resampled
 raster and the y raster are the same except for the number of cells.

 I will be grateful for any help.






[[alternative HTML version deleted]]



--

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


End of R-sig-Geo Digest, Vol 116, Issue 7

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] seemingly unresolved problem with predict() in package raster

2013-04-05 Thread Gonzalez-Mirelis Genoveva
Many thanks for looking into this Robert!

From: Robert J. Hijmans [mailto:r.hijm...@gmail.com]
Sent: April-04-13 17:53
To: Gonzalez-Mirelis Genoveva
Cc: r-sig-geo@r-project.org
Subject: Re: [R-sig-Geo] seemingly unresolved problem with predict() in package 
raster


cforest with factors are currently not supported (although they may work in 
some cases). I will change the predict function to make it more general by 
adding a 'levels' argument such that you can indicate (for models with a 
non-standard structure such as cforest) which variables are factors and what 
their levels are. Robert

On Thu, Apr 4, 2013 at 4:22 AM, Gonzalez-Mirelis Genoveva 
genoveva.gonzalez-mire...@imr.nomailto:genoveva.gonzalez-mire...@imr.no 
wrote:
Hi all,



I have a problem with the function raster::predict very similar to the one 
described here [1], [2] using raster package version 2.0-41 and party package 
version 1.0-6, where my model is a conditional inference forest 
(party::cforest). Could not find a solution in either post.



The problem is the following: when I use the function predict() I get an error 
relating to a mismatch between the levels of factors in the data frame used to 
fit the model and those of the raster layers used to predict to the whole 
surface.



The only difference that I can see is that the levels of the factors in the 
model are as follows (e.g.):



 morphrec.levels-levels(v$morphrec)

 morphrec.levels

[1] 1 2 3 4 5 6



Whereas if I ask for the unique values of the same raster layer (where values 
were extracted from in an earlier step) that is now being used to predict a 
value for the response variable, I see the following:



 morphrec.values-sort(unique(getValues(morphrec)))

 morphrec.values

[1] 1 2 3 4 5 6



When I try running predict, the following happens:



r - predict(predictors, confor.dens, type='response',OOB=TRUE)

Loading required package: tcltk

Loading Tcl/Tk interface ... done Error in checkData(oldData, RET) :

  Classes of new data do not match original data



 predictors

class   : RasterStack

dimensions  : 2787, 2293, 6390591, 7  (nrow, ncol, ncell, nlayers) resolution  
: 200, 200  (x, y)

extent  : 296387.5, 754987.5, 7488413, 8045813  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=utm +zone=33 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0

names   :   bathy,   slope, tri,   grainsize,   landscape,  
sedenv,morphrec

min values  :  0.44850001,  0.02432192,  0.04429007,  1., 21.,  
1.,  1.

max values  :  2912.94849,46.13418,43.59974,   300.0,   431.0,  
   5.0, 6.0



 confor.dens



 Random Forest using Conditional Inference Trees



Number of trees:  1000



Response:  density

Inputs:  bathy, slope, tri, grainsize, landscape, sedenv, morphrec Number of 
observations:  1020





Is there any way of telling predict() that the values of some raster layers 
will have to be considered characters? Or am I facing a different problem 
entirely?



Any help will be much appreciated. I have been working on creating a small, 
reproducible example, but I can't seem to get the exact same behavior.



Regards,

Geno



[1] 
http://r-sig-geo.2731867.n2.nabble.com/problems-with-predict-in-package-raster-td6627291.html#a6628041

[2] 
http://r-sig-geo.2731867.n2.nabble.com/new-function-predict-package-raster-td5796744.html#a5816769




Genoveva Gonzalez Mirelis, Scientist
Institute of Marine Research
Nordnesgaten 50
5005 Bergen, Norway
+47 5523 6376tel:%2B47%205523%206376


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.orgmailto:R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] seemingly unresolved problem with predict() in package raster

2013-04-04 Thread Gonzalez-Mirelis Genoveva
Hi all,



I have a problem with the function raster::predict very similar to the one 
described here [1], [2] using raster package version 2.0-41 and party package 
version 1.0-6, where my model is a conditional inference forest 
(party::cforest). Could not find a solution in either post.



The problem is the following: when I use the function predict() I get an error 
relating to a mismatch between the levels of factors in the data frame used to 
fit the model and those of the raster layers used to predict to the whole 
surface.



The only difference that I can see is that the levels of the factors in the 
model are as follows (e.g.):



 morphrec.levels-levels(v$morphrec)

 morphrec.levels

[1] 1 2 3 4 5 6



Whereas if I ask for the unique values of the same raster layer (where values 
were extracted from in an earlier step) that is now being used to predict a 
value for the response variable, I see the following:



 morphrec.values-sort(unique(getValues(morphrec)))

 morphrec.values

[1] 1 2 3 4 5 6



When I try running predict, the following happens:



r - predict(predictors, confor.dens, type='response',OOB=TRUE)

Loading required package: tcltk

Loading Tcl/Tk interface ... done Error in checkData(oldData, RET) :

  Classes of new data do not match original data



 predictors

class   : RasterStack

dimensions  : 2787, 2293, 6390591, 7  (nrow, ncol, ncell, nlayers) resolution  
: 200, 200  (x, y)

extent  : 296387.5, 754987.5, 7488413, 8045813  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=utm +zone=33 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0

names   :   bathy,   slope, tri,   grainsize,   landscape,  
sedenv,morphrec

min values  :  0.44850001,  0.02432192,  0.04429007,  1., 21.,  
1.,  1.

max values  :  2912.94849,46.13418,43.59974,   300.0,   431.0,  
   5.0, 6.0



 confor.dens



 Random Forest using Conditional Inference Trees



Number of trees:  1000



Response:  density

Inputs:  bathy, slope, tri, grainsize, landscape, sedenv, morphrec Number of 
observations:  1020





Is there any way of telling predict() that the values of some raster layers 
will have to be considered characters? Or am I facing a different problem 
entirely?



Any help will be much appreciated. I have been working on creating a small, 
reproducible example, but I can't seem to get the exact same behavior.



Regards,

Geno



[1] 
http://r-sig-geo.2731867.n2.nabble.com/problems-with-predict-in-package-raster-td6627291.html#a6628041

[2] 
http://r-sig-geo.2731867.n2.nabble.com/new-function-predict-package-raster-td5796744.html#a5816769




Genoveva Gonzalez Mirelis, Scientist
Institute of Marine Research
Nordnesgaten 50
5005 Bergen, Norway
+47 5523 6376


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo