causality | Tools for causal analysis | Analytics library
kandi X-RAY | causality Summary
kandi X-RAY | causality Summary
This package contains tools for causal analysis using observational (rather than experimental) datasets.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculates the expected value
- PDF of the covariance function
- Estimate the model
- Estimate the imbalance of each confound
- Calculate the imbalance ratio
- Estimate the ATC coefficient
- Determines if the given assignment matches the given assignment
- Calculate the confidence interval for a given distribution
- Estimate the weight of an effect
- Estimate the predicted effect probability
- Wrapper for plot
- Compute z mean
- Calculate the bootstrapped mean plot
- Calculates the bootstrap statistic for a given dataframe
- Compute the integration function
- Evaluate the expectation function
- Returns a set of adjacables that satisfy the given effect
- Return whether the assumption is satisfied
- Finds predecessors of given causes
causality Key Features
causality Examples and Code Snippets
Community Discussions
Trending Discussions on causality
QUESTION
I want to build an iteration using the Stata FAQ here. The second method seems fitting for my case. I have built the following code:
...ANSWER
Answered 2021-Dec-15 at 18:22display
of the current level is easy enough, say:
QUESTION
I have two vectors x
and y
ANSWER
Answered 2021-Nov-22 at 13:34These procedures fail because waldtest()
is looking for attributes/methods that don't exist in/for fitted model objects returned by fast.lm()
and lm()
with data.table input and I don't believe there is an easy fix.
However, if you want to test whether the model including y
and a constant is "better" than the constant-only model you can use summary()
(which has a method for objects of class fast.lm
).
E.g. from the last line of summary(fit_3)
you'll get
QUESTION
I've been studying the memory model and saw this (quote from https://research.swtch.com/hwmm):
...ANSWER
Answered 2021-Sep-11 at 08:47It makes some sense to call StoreLoad reordering an effect of the store buffer because the way to prevent it is with mfence
or a lock
ed instruction that drains the store buffer before later loads are allowed to read from cache. Merely serializing execution (with lfence
) would not be sufficient, because the store buffer still exists. Note that even sfence ; lfence
isn't sufficient.
Also I assume P5 Pentium (in-order dual-issue) has a store buffer, so SMP systems based on it could have this effect, in which case it would definitely be due to the store buffer. IDK how thoroughly the x86 memory model was documented in the early days before PPro even existed, but any naming of litmus tests done before that might well reflect in-order assumptions. (And naming after might include still-existing in-order systems.)
You can't tell which effect caused StoreLoad reordering. It's possible on a real x86 CPU (with a store buffer) for a later load to execute before the store has even written its address and data to the store buffer.
And yes, executing a store just means writing to the store buffer; it can't commit from the SB to L1d cache and become visible to other cores until after the store retires from the ROB (and thus is known to be non-speculative).
(Retirement happens in-order to support "precise exceptions". Otherwise, chaos ensues and discovering a mis-predict might mean rolling back the state of other cores, i.e. a design that's not sane. Can a speculatively executed CPU branch contain opcodes that access RAM? explains why a store buffer is necessary for OoO exec in general.)
I can't think of any detectable side-effect of the load uop executing before the store-data and/or store-address uops, or before the store retires, rather than after the store retires but before it commits to L1d cache.
You could force the latter case by putting an lfence
between the store and the load, so the reordering is definitely caused by the store buffer. (A stronger barrier like mfence, a locked instruction, or a serializing instruction like cpuid
, will all block the reordering entirely by draining the store buffer before the later load can execute. As an implementation detail, before it can even issue.)
A normal out of order exec treats all instructions as speculative, only becoming non-speculative when they retire from the ROB, which is done in program order to support precise exceptions. (See Out-of-order execution vs. speculative execution for a more in-depth exploration of that idea, in the context of Intel's Meltdown vulnerability.)
A hypothetical design with OoO exec but no store buffer would be possible. It would perform terribly, with each store having to wait for all previous instructions to be definitively known to not fault or otherwise be mispredicted / mis-speculated before the store can be allowed to execute.
This is not quite the same thing as saying that they need to have already executed, though (e.g. just executing the store-address uop of an earlier store would be enough to know it's non-faulting, or for a load doing the TLB/page-table checks will tell you it's non-faulting even if the data hasn't arrived yet). However, every branch instruction would need to be already executed (and known-correct), as would every ALU instruction like div
that can.
Such a CPU also doesn't need to stop later loads from running before stores. A speculative load has no architectural effect / visibility, so it's ok if other cores see a share-request for a cache line which was the result of a mis-speculation. (On a memory region whose semantics allow that, such as normal WB write-back cacheable memory). That's why HW prefetching and speculative execution work in normal CPUs.
The memory model even allows StoreLoad ordering, so we're not speculating on memory ordering, only on the store (and other intervening instructions) not faulting. Which again is fine; speculative loads are always fine, it's speculative stores that we must not let other cores see. (So we can't do them at all if we don't have a store buffer or some other mechanism.)
(Fun fact: real x86 CPUs do speculate on memory ordering by doing loads out of order with each other, depending on addresses being ready or not, and on cache hit/miss. This can lead to memory order mis-speculation "machine clears" aka pipeline nukes (machine_clears.memory_ordering
perf event) if another core wrote to a cache line between when it was actually read and the earliest the memory model said we could. Or even if we guess wrong about whether a load is going to reload something stored recently or not; memory disambiguation when addresses aren't ready yet involves dynamic prediction so you can provoke machine_clears.memory_ordering
with single-threaded code.)
Out-of-order exec in P6 didn't introduce any new kinds of memory re-ordering because that could have broken existing multi-threaded binaries. (At that time mostly just OS kernels, I'd guess!) That's why early loads have to be speculative if done at all. x86's main reason for existence it backwards compat; back then it wasn't the performance king.
Re: why this litmus test exists at all, if that's what you mean?
Obviously to highlight something that can happen on x86.
Is StoreLoad reordering important? Usually it's not a problem; acquire / release synchronization is sufficient for most inter-thread communication about a buffer being ready to read, or more generally a lock-free queue. Or to implement mutexes. ISO C++ only guarantees that mutexes lock / unlock are acquire and release operations, not seq_cst.
It's pretty rare that an algorithm depends on draining the store buffer before a later load.
Say I somehow observed this litmus test on an x86 machine,
Fully working program that verifies that this reordering is possible in real life on real x86 CPUs: https://preshing.com/20120515/memory-reordering-caught-in-the-act/. (The rest of Preshing's articles on memory ordering are also excellent. Great for getting a conceptual understanding of inter-thread communication via lockless operations.)
QUESTION
I have read several papers claiming to compare multiple entities (firms, countries, etc.) at the same time using Granger Causality. They usually group countries in east, west, north and south or urban / non urban (for example).
E.g. the public dataset by "Grunfeld" in the plm
package has the following form:
| firm | year | inv | value | capital |
I have a similar dataset which I aim to explore using Granger Causality. My time variable is from 1990 to 2020.
country_ID country_type year sum var_A var_B ... 1 1 2000 323 32 213 2 1 2000 13 0 7 3 2 2000 12 7 0 4 1 2000 0 0 0 5 2 2000 323 13 56Stata does not return anything useful running this through, I suppose it's because of too many countries.
Is it even possible to take a subset of my dataset, say country_type = 1
and run a Granger over the countries included? Or do I have to sum up all countries in country_type
in order to run Granger?
One paper I looked into is (p.1310): "The Causality Analysis between Transportation and Regional Development in City-level China" by He et al. (2019).
...ANSWER
Answered 2021-Aug-27 at 09:29You do not write which of Stata's commands you use. If you have panel data, you may want to use the panel Granger (non-)causality test by Dumitrescu/Hurlin (2012), implemented in Stata's user contributed command xtgcause
and in R's plm
package as pgrangertest
.
Below is an example of how to use pgrangertest
with the Grunfeld dataset in R. The help page has references to the literature and some more information on how use more options (?pgrangertest
):
QUESTION
This question came to me after reading this answer.
Code example:
...ANSWER
Answered 2021-Feb-23 at 01:56Partial answer: how "unsafe republication" works on OpenJDK today.
(This is not the ultimate general answer I would like to get, but at least it shows what to expect on the most popular Java implementation)
In short, it depends on how the object was published initially:
- if initial publication is done through a volatile variable, then "unsafe republication" is most probably safe, i.e. you will most probably never see the object as partially constructed
- if initial publication is done through a synchronized block, then "unsafe republication" is most probably unsafe, i.e. you will most probably be able to see object as partially constructed
Most probably is because I base my answer on the assembly generated by JIT for my test program, and, since I am not an expert in JIT, it would not surprise me if JIT generated totally different machine code on someone else's computer.
For tests I used OpenJDK 64-Bit Server VM (build 11.0.9+11-alpine-r1, mixed mode) on ARMv8.
ARMv8 was chosen because it has a very relaxed memory model, which requires memory barrier instructions in both publisher and reader threads (unlike x86).
1. Initial publication through a volatile variable: most probably safe
Test java program is like in the question (I only added one more thread to see what assembly code is generated for a volatile write):
QUESTION
I have a data frame with a column named title, I want to apply textdistance to check similarities between different titles and remove any rows with similar titles (based on a specific threshold). Is there away to do that directly, or I need to define a custom function and group similar titles togother before removing "duplicates" (titles that are similar)? A sample would look like this.
...ANSWER
Answered 2021-Feb-13 at 10:03So I have done it in a different way. I have created a column to mask which rows to keep and to delete. I accessed the target row and checked the similarity with the rows below it.
QUESTION
I'm currently trying to run a granger causality analysis in R/R Studio. I am receiving errors about aliased coefficients when using the function grangertest()
. From my understanding, this occurs because there is perfect multicolinearity between the variables.
Due to having a very large number of pairwise comparisons (e.g. 200+), I would like to simply run the granger with the aliased coefficients as per normal rather than returning an error. According to one answer here, the solution is or was to add set singular.ok=TRUE
, but either I am doing it incorrectly the answer s out of date. I've tried checking the documentation, but have come up empty. Any help would be appreciated.
ANSWER
Answered 2021-Jan-17 at 06:58After some investigation and emailing the creator of the grangertest package, they sent me this solution. The solution should run on aliased variables when granger test does not. When the variables are not aliased, the solution should give the same values as the normal granger test.
QUESTION
I am wanting to conduct granger causality between several different pairs of variables for country year data. I seem to be able to get it working outside of a loop/function, but am having some trouble integrating it with the remainder of my code. I've provided code for a minimal working example and desired output below. Any help would be greatly appreciated. Thankyou in advance!
EDIT: I should have specified more clearly in the original post. Each column in this generated data contains time series data for multiple countries. I want to average across the countries and then perform granger on those variables) using the same method detailed below
Code to Simulate Time Series Data
...ANSWER
Answered 2021-Jan-08 at 01:15You can apply the function to all combinations in combn
function itself, so no need to have a separate lapply
call.
QUESTION
I'm having a problem where I want to create a column of 4 labels. However, when I try to create these, the labels I make eat into re-labeling the first label I have assigned. For example I am looking to create a label
column like this:
ANSWER
Answered 2020-Sep-21 at 10:28You can use case_when
or nested ifelse
statements so that every row will satisfy only one condition based on their occurrence.
QUESTION
I try to fit an ARIMAX model to figure out whether the containment measures (using the Government response stringency index, numbers from 0 to 100) are having a significant effect on the daily new cases rate. I also want to add test rates.
I programmed everything in R (every ts is stationary,...) and did the Granger causality test. Result: Pr(>F)
is greater than 0.05. Therefore the null hypothesis of NO Granger causality can be rejected and the new cases rate and the containment measures have reverse causality.
Is there any possibility to transform the variable "stringency index" and continue with an ARIMAX model? If so, how to do this in R?
ANSWER
Answered 2020-Nov-26 at 21:11In R you have "forecast" package to build ARIMA models. Recall, that there is a difference between true ARIMAX models and linear regressions with ARIMA errors. Check this post by Rob Hyndman (forecast package author) for more detailed information: The ARIMAX model muddle
Here are Rob Hyndman's examples to fit a linear regression with ARIMA errors - check more information here:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install causality
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page