这是我的data.frame:
my_pipe[1]
有任何软件包可以帮助我进行简单的自回归线性回归,而不必在data.frame中创建另一个列吗? 这就是我想要的:
public class MainActivityCollection extends FragmentActivity{ DemoCollectionPagerAdapter mDemoCollectionPagerAdapter; ViewPager mViewPager; TranslateAnimation animation; ImageView title; @Override public void onBackPressed() { super.onBackPressed(); finish(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitycollection); title=(ImageView)findViewById(R.id.title); mViewPager = (ViewPager) findViewById(R.id.pager); Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE) .getBoolean("isFirstRun", true); if (isFirstRun) { //show start activity startActivity(new Intent(getApplicationContext(), Welcome.class)); } getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit() .putBoolean("isFirstRun", false).commit(); animation = new TranslateAnimation(0.0f, 0.0f, -200.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo) animation.setDuration(1200); title.startAnimation(animation); title.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Uri uri = Uri.parse("http://www.sairam.edu.in"); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); // getSupportFragmentManager. mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager()); // Set up action bar. // Set up the ViewPager, attaching the adapter. mViewPager.setAdapter(mDemoCollectionPagerAdapter); } private class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter { public DemoCollectionPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { Fragment fragment; switch (position) { case 0: fragment = new LatestNews(); return fragment; case 1: fragment = new News(); return fragment; case 2: fragment = new Events(); return fragment; default: break; } return null; } @Override public int getCount() { return 3; } @Override public CharSequence getPageTitle(int position) { CharSequence title = null; if (position == 0) { title = "Latest News"; } else if (position == 1) { title = "News"; }else if (position == 2) { title = "Events"; } return title; } } }
感谢。
答案 0 :(得分:2)
以下是一些方法:
1)dyn
library(dyn)
Lag <- function(x, k = 1) lag(x, -k)
dyn$lm(X1 ~ Lag(X1) + Lag(X2) - 1, as.zoo(GDP))
,并提供:
Call:
lm(formula = dyn(X1 ~ Lag(X1) + Lag(X2) - 1), data = as.zoo(GDP))
Coefficients:
Lag(X1) Lag(X2)
-0.1876 0.0772
请注意,这也有效,但正如我们上面所做的那样定义Lag
会让它看起来更漂亮。
dyn$lm(X1 ~ lag(X1, -1) + lag(X2, -1) - 1, as.zoo(GDP))
2)vars
library(vars)
VAR(GDP, type = "none")
,并提供:
VAR Estimation Results:
=======================
Estimated coefficients for equation X1:
=======================================
Call:
X1 = X1.l1 + X2.l1
X1.l1 X2.l1
-0.18755204 0.07719922
Estimated coefficients for equation X2:
=======================================
Call:
X2 = X1.l1 + X2.l1
X1.l1 X2.l1
0.4433822 0.2558610
或者如果我们只是想看第一个等式:
VAR(GDP, type = "none")[[1]]$X1
,并提供:
Call:
lm(formula = y ~ -1 + ., data = datamat)
Coefficients:
X1.l1 X2.l1
-0.1876 0.0772
3)没有包
n <- nrow(GDP)
lm(X1[-1] ~ X1[-n] + X2[-n] - 1, GDP)
,并提供:
Call:
lm(formula = X1[-1] ~ X1[-n] + X2[-n] - 1, data = GDP)
Coefficients:
X1[-n] X2[-n]
-0.1876 0.0772
注意我们在上面的例子中使用了以下GDP。
GDP <-
structure(list(X1 = c(-0.480007101227991, -0.710506834821923,
-1.4008090378277, 0.234161619712456, 0.0798157911638669, -0.835197270889505,
0.598254213927639, -1.14352681562672, 1.03688327045929, 0.660297071029499,
-0.351328818974587, 0.790545641075689, -0.792678099784052, -0.357614703160382,
0.314291502993829, -0.431642261560374, 0.316918597548564, 0.5209261331865,
1.0013650951443, 1.05596920913398, -0.753506630185664, -1.4890660967781,
1.43183749932514, -0.423639570640277, 0.637317561276307), X2 = c(0.474962739361749,
-2.39846608215569, -0.98006715899912, -0.0271182048898923, 0.0296705736957689,
-1.24925308595335, -0.893230759394588, 0.241972221010069, -0.431946104440377,
-0.638101222832251, 0.844712933353179, 0.883298568281938, 0.996083349802754,
1.89504374477663, -0.148165464503539, 1.15286878557205, -0.425104835813157,
-1.38572745123415, 1.52226162248381, 1.55272897266444, 1.35700497284096,
0.389532599186254, 0.256357476163037, 1.29116051537444, -0.440232029770923
)), .Names = c("X1", "X2"), row.names = c(NA, -25L), class = "data.frame")