predict.blackbox: Predict method of blackbox objects

Description Usage Arguments Value Author(s) See Also Examples

View source: R/basicspace.R

Description

predict.blackbox reads an blackbox object and uses the estimates to generate a matrix of predicted values.

Usage

1
2
  ## S3 method for class 'blackbox'
predict(object, dims=1, ...)             

Arguments

object

A blackbox output object.

dims

Number of dimensions used in prediction. Must be equal to or less than number of dimensions used in estimation.

...

Ignored.

Value

A matrix of predicted values generated from the parameters estimated from a blackbox object.

Author(s)

Keith Poole ktpoole@uga.edu

Howard Rosenthal hr31@nyu.edu

Jeffrey Lewis jblewis@ucla.edu

James Lo lojames@usc.edu

Royce Carroll rcarroll@rice.edu

See Also

'blackbox', 'Issues1980'

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Estimate blackbox object from example and call predict function
data(Issues1980)
Issues1980[Issues1980[,"abortion1"]==7,"abortion1"] <- 8	#missing recode
Issues1980[Issues1980[,"abortion2"]==7,"abortion2"] <- 8	#missing recode

### This command conducts estimates, which we instead load using data()
# Issues1980_bb <- blackbox(Issues1980,missing=c(0,8,9),verbose=FALSE,dims=3,minscale=8)
data(Issues1980_bb)
prediction <- predict.blackbox(Issues1980_bb,dims=3)

## Examine predicted vs. observed values for first 10 respondents
## Note that 4th and 6th respondents are NA because of missing data
Issues1980[1:10,]
prediction[1:10,]

## Check correlation across all predicted vs. observed, excluding missing values
prediction[which(Issues1980 %in% c(0,8,9))] <- NA
cor(as.numeric(prediction), as.numeric(Issues1980), use="pairwise.complete")

Example output

Loading required package: tools

## BASIC SPACE SCALING PACKAGE
## 2009 - 2021
## Keith Poole, Howard Rosenthal, Jeffrey Lewis, James Lo, and Royce Carroll
## Support provided by the U.S. National Science Foundation
## NSF Grant SES-0611974

   libcon1 defense govserv inflation abortion1 taxcut libcon2 govhelpmin russia
1        0       7       5         4         2      2       6          7      4
2        4       4       6         7         1      0       0          1      2
3        6       3       0         0         1      0       0          0      0
4        5       6       2         8         2      0       9          9      9
5        3       4       2         4         4      0       8          3      3
6        5       5       4         0         3      2       9          9      9
7        8       2       6         5         3      4       8          1      7
8        2       7       7         6         2      1       6          4      1
9        6       7       2         2         3      5       6          6      5
10       5       4       2         5         2      1       4          5      6
   womenrole govjobs equalrights busing abortion2
1          7       5           2      7         2
2          3       1           1      3         3
3          3       1           1      1         2
4          9       9           0      9         9
5          4       7           0      6         3
6          9       9           0      9         9
7          1       1           0      7         2
8          1       8           1      7         1
9          2       6           2      6         2
10         1       6           1      6         2
    libcon1  defense  govserv inflation abortion1   taxcut  libcon2 govhelpmin
1  5.436112 6.267710 4.585953  4.869010  1.902599 2.775569 5.266833   5.537233
2  2.891664 3.949504 7.199578  5.848851  2.496070 2.167001 2.862174   2.300303
3  3.393584 2.012436 4.493996  4.323281  2.337468 2.930525 3.114744   1.689159
4        NA       NA       NA        NA        NA       NA       NA         NA
5  4.772816 4.577460 2.518198  3.028964  2.949986 3.310902 4.780766   4.741694
6        NA       NA       NA        NA        NA       NA       NA         NA
7  2.730068 5.150082 6.994781  5.299121  3.389610 2.133395 3.054735   3.359883
8  3.174996 4.986914 6.749169  5.432639  2.896262 2.225085 3.322011   3.372961
9  5.170708 5.629226 1.993527  2.625346  3.256616 3.391778 5.323245   5.869060
10 4.246276 5.591154 3.712291  3.457386  3.468704 2.946850 4.519457   5.100956
      russia womenrole  govjobs equalrights   busing abortion2
1   5.222231  5.822348 4.756192    4.353727 6.932339  1.712149
2   1.108624  3.226022 0.824088    1.648064 4.168123  2.426978
3  -2.610414  3.423266 0.572360    2.546466 3.318591  2.420292
4         NA        NA       NA          NA       NA        NA
5   2.766810  2.666016 5.070296    3.199410 6.064738  2.808590
6         NA        NA       NA          NA       NA        NA
7   4.011054  1.104344 2.801240    0.709836 5.221188  3.172302
8   3.374814  2.456964 2.492920    1.525484 5.171074  2.725458
9   4.999778  2.169362 6.748264    3.256360 7.104929  3.019120
10  5.013970  1.376650 5.630120    2.162656 6.559797  3.217432
[1] 0.8242331

basicspace documentation built on Jan. 11, 2020, 9:32 a.m.