[R-sig-Geo] raster::predict: more than one single output
Agustin Lobo
alobolistas at gmail.com
Mon Sep 26 12:04:26 CEST 2011
Thanks. The help page is a bit confusing on this:
"index Integer. To select the column if predict.'model' returns a
matrix with multiple columns"
in this case, predict.lm() does not return a matrix but a list, which
2nd and 3rd components are
matrix objects. Hence the confusion: I assumed only the first
component was returned.
Agus
2011/9/24 Robert J. Hijmans <r.hijmans at gmail.com>:
> Hi Agus,
>
> You can use the index argument for that (but I admit that the function
> should detect this automatically). If you expect two numbers for each cell,
> you can do
>
> predict(object=PCAtoMedian_6yrs,model=srndpc20000lda, index=1:2)
>
> Robert
>
> On Sat, Sep 24, 2011 at 2:48 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
>
>> I'm using raster::predict using predict.lda():
>>
>> > srndpc20000lda <- lda(srndpcclasses[,1:5],srndpcclasses[,37])
>> > PCAtoMedian_6yrsclass20000 <-
>> predict(object=PCAtoMedian_6yrs,model=srndpc20000lda)
>> > PCAtoMedian_6yrsclass20000
>> class : RasterLayer
>> dimensions : 1289, 1289, 1661521 (nrow, ncol, ncell)
>> resolution : 0.008928571, 0.008928571 (x, y)
>> extent : 30.99554, 42.50446, 1.495536, 13.00446 (xmin, xmax, ymin,
>> ymax)
>> coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
>> +towgs84=0,0,0
>> values : in memory
>> min value : 1
>> max value : 4
>>
>> But I would also need the rest of the output provided by
>> predict.lda(), in particular a layer with the posterior
>> probabilities to mask out those pixels which do not have a high
>> probability for any of the classes.
>> From the help page of MASS::predict.lda():
>>
>> Value
>> a list with components
>>
>> class The MAP classification (a factor)
>> posterior posterior probabilities for the classes
>> x the scores of test cases on up to dimen discriminant variables
>>
>> As far as I understand, only "class" is returned by raster::predict.
>> Am I wrong and there is actually a way to get the posteriors?
>> Otherwise, could that be added in the future?
>>
>> Thanks
>>
>> Agus
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> 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