[R-sig-Geo] create rasters using pca components of bioclimatic variables

Robert J. Hijmans r.hijmans at gmail.com
Sun Nov 24 04:24:45 CET 2013


You are using 'Bio01' where it probably should be 'myExpl'. I would
have thought that this should have been pretty clear from the working
example that I sent.
Robert

On Thu, Nov 21, 2013 at 10:47 AM, Andre <pintodasilva.a at gmail.com> wrote:
> Thanks Robert.
>
> I got this error
>
> x <- predict(Bio01, pca, index=1:3)
> Error in predict.princomp(model, blockvals, ...) :
>   'newdata' does not have named columns matching one or more of the
> original columns
>
> What is missing in the code?
>
> Thanks
>
>
> On 21 November 2013 18:41, Robert Hijmans [via R-sig-geo] <
> ml-node+s2731867n7585159h14 at n2.nabble.com> wrote:
>
>> Andre,
>>
>> The below is slightly modified from the example in
>> ?raster::predict
>>
>> library(raster)
>> logo <- brick(system.file("external/rlogo.grd", package="raster"))
>> sr <- sampleRegular(logo, min(100000, ncell(logo)))
>> pca <- prcomp(sr)
>> x <- predict(logo, pca, index=1:3)
>> plot(x)
>>
>>
>> Robert
>>
>> On Thu, Nov 21, 2013 at 7:25 AM, Andre <[hidden email]<http://user/SendEmail.jtp?type=node&node=7585159&i=0>>
>> wrote:
>>
>> > Hi,
>> >
>> > I performed pca in 4 bioclimatic variables using princomp.
>> >
>> > ##stack rasters
>> > myExpl <- raster::stack (Bio01,Bio02,Bio03,Bio04)
>> > ##read as data.frame
>> > m <- as.data.frame(myExpl)
>> > ##pca (here I used formula to activate na.action)
>> > pca <- princomp(formula = ~., data = m, cor = TRUE,
>> na.action=na.exclude)
>> >
>> > Now I would like to create rasters (with the same size as BIO01) for
>> each
>> > component of the PCA to use them as input in biomod2.
>> >
>> > What is the best way to do this?
>> >
>> > Many thanks,
>> >
>> > Andre
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/create-rasters-using-pca-components-of-bioclimatic-variables-tp7585158.html
>> > Sent from the R-sig-geo mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > [hidden email] <http://user/SendEmail.jtp?type=node&node=7585159&i=1>
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=7585159&i=2>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://r-sig-geo.2731867.n2.nabble.com/create-rasters-using-pca-components-of-bioclimatic-variables-tp7585158p7585159.html
>>  To unsubscribe from create rasters using pca components of bioclimatic
>> variables, click here<http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7585158&code=cGludG9kYXNpbHZhLmFAZ21haWwuY29tfDc1ODUxNTh8Nzg5MzY3ODc2>
>> .
>> NAML<http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
> --
> *André P. Silva*
> PhD Candidate
> Department of Animal Ecology
> Evolutionary Biology Centre
> Uppsala University
> Norbyvägen 18D
> 752 36 Uppsala
> Sweden
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/create-rasters-using-pca-components-of-bioclimatic-variables-tp7585158p7585160.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list