物流模型中的Bootstrap

时间:2016-01-21 15:59:40

标签: r bootstrapping logistic-regression

我有以下逻辑模型

public class DropboxSampleActivity extends Activity {

private ListView listViewDropbox;
private ArrayAdapter<String> adapter = null;
private static String URL_FILE_DROPBOX = "https://www.dropbox.com/s/xxxxxxxxxxxx/xxxxxxxxxxxx?dl=1";
private ArrayList<String> listElementItem;


@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_dropbox_list);

    super.onCreate(savedInstanceState);
    listViewDropbox = (ListView) findViewById(R.id.listViewDropbox);
    DropboxItemAsyncTask dropboxItemAsyncTask = new DropboxItemAsyncTask();
    dropboxItemAsyncTask.execute();
}

class DropboxItemAsyncTask extends AsyncTask {

    protected Integer doInBackground(Object[] params) {

        try {
            listElementItem = new ArrayList<>();
            URLConnection conn = new URL(URL_FILE_DROPBOX).openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "UTF-8"), 8);
            String line = null;
            while ((line = reader.readLine()) != null) {
                listElementItem.add(line);
            }
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    protected void onPostExecute(Object o) {
        if (adapter == null) {
            adapter = new ArrayAdapter(DropboxSampleActivity.this,
                    android.R.layout.simple_list_item_1, listElementItem);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    listViewDropbox.setAdapter(adapter);
                }
            });
        } else {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    adapter.notifyDataSetChanged();
                }
            });

        }
    }
};

我计算模型的&#34;得分&#34;,X,例如X = $ null.deviance- $ deviance。在这种情况下,X = 138.63-125.09。 现在,我想使用bootstrap来计算得分的平均值和置信区间。我怎样才能在R?

中实现这一点

1 个答案:

答案 0 :(得分:1)

查看包boot。下面是一个适合您案例的模拟示例:

library(boot)
x <- rnorm(100)
Y <- exp(x + rnorm(100)) > 1
datasim <- data.frame(Y, x)

dDeviance <- function(data, indices){
  fit <- glm(formula = Y ~ ., family = binomial, data = data[indices, ])
  with(fit, null.deviance - deviance)
}
boot(data = datasim, statistic = dDeviance, R = 100)

输出:

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = datasim, statistic = dDeviance, R = 100)


Bootstrap Statistics :
    original   bias    std. error
t1* 41.02692 1.445287    9.712626